From f67b17d19251c5ba0b06bc8684a886190e3448b1 Mon Sep 17 00:00:00 2001 From: Daniel Persson Date: Tue, 18 Oct 2016 13:56:02 +0100 Subject: [PATCH 1/9] Adding pause support from external components. --- paper-audio-player.html | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/paper-audio-player.html b/paper-audio-player.html index ee7fcc6..b76610c 100755 --- a/paper-audio-player.html +++ b/paper-audio-player.html @@ -493,6 +493,10 @@ player.isPlaying = false; }, + pause: function() { + var player = this; + player.$.audio.pause(); + } // when Player ended playing an audio file From b6a301bd69a674f9841e8bd2a504c46a888e5438 Mon Sep 17 00:00:00 2001 From: Daniel Persson Date: Tue, 18 Oct 2016 14:05:20 +0100 Subject: [PATCH 2/9] Those commas. --- paper-audio-player.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/paper-audio-player.html b/paper-audio-player.html index b76610c..665524e 100755 --- a/paper-audio-player.html +++ b/paper-audio-player.html @@ -496,7 +496,7 @@ pause: function() { var player = this; player.$.audio.pause(); - } + }, // when Player ended playing an audio file From 195f0e013f38d7235d4651e39e0df4ae27eeb5be Mon Sep 17 00:00:00 2001 From: Daniel Persson Date: Tue, 18 Oct 2016 18:01:47 +0100 Subject: [PATCH 3/9] Check if playing before pausing. --- paper-audio-player.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/paper-audio-player.html b/paper-audio-player.html index 665524e..008ee2e 100755 --- a/paper-audio-player.html +++ b/paper-audio-player.html @@ -495,7 +495,7 @@ pause: function() { var player = this; - player.$.audio.pause(); + if ( player.isPlaying ) player.$.audio.pause(); }, // when Player ended playing an audio file From 6fadc0de5e29a3e01de4cad1b7309abb4e9dce6e Mon Sep 17 00:00:00 2001 From: Daniel Persson Date: Wed, 26 Oct 2016 07:14:04 +0200 Subject: [PATCH 4/9] Added testcase --- paper-audio-player.html | 4 ++++ test/basic-test.html | 10 +++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/paper-audio-player.html b/paper-audio-player.html index 008ee2e..01a96dc 100755 --- a/paper-audio-player.html +++ b/paper-audio-player.html @@ -309,6 +309,10 @@ type: Boolean, value: false }, + isPlaying: { + type: Boolean, + value: false + }, preload: { type: String, value: 'auto' diff --git a/test/basic-test.html b/test/basic-test.html index 5da66e2..a7adc1d 100755 --- a/test/basic-test.html +++ b/test/basic-test.html @@ -33,6 +33,14 @@ assert.equal(basicPlayer.$.audio.src, 'http://nadikun.com/audio/suit-and-tie-oscar-wylde-remix.mp3'); }); + test('defines the "src" property', function() { + assert.notOk(basicPlayer.isPlaying); + basicPlayer.playPause(); + assert.ok(basicPlayer.isPlaying); + basicPlayer.pause(); + assert.notOk(basicPlayer.isPlaying); + }); + test('defines the "color" property', function() { assert.equal(basicPlayer.color, '#F05C38'); assert.equal(basicPlayer.querySelector('#progress').style.backgroundColor, 'rgb(240, 92, 56)'); @@ -56,4 +64,4 @@ - + \ No newline at end of file From 89ec23f781bded2071d6883a2cd5d65f30dc1fbf Mon Sep 17 00:00:00 2001 From: Daniel Persson Date: Thu, 16 Mar 2017 11:29:11 +0100 Subject: [PATCH 5/9] Added media session support. --- paper-audio-player.html | 44 +++++++++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 10 deletions(-) diff --git a/paper-audio-player.html b/paper-audio-player.html index 01a96dc..79f6d2c 100755 --- a/paper-audio-player.html +++ b/paper-audio-player.html @@ -381,20 +381,44 @@ }, - // Play/Pause controls + _startPlaying() { + player.$.audio.play().then(_ => { + if ('mediaSession' in navigator) { + navigator.mediaSession.metadata = new MediaMetadata({ + title: this.title, + }); + + navigator.mediaSession.setActionHandler('play', this.playPause()); + navigator.mediaSession.setActionHandler('pause', this.pause()); + navigator.mediaSession.setActionHandler('seekbackward', + this._skipReverseByInterval(new CustomEvent('skip', { 'detail': {'key': 'left'} })) + ); + navigator.mediaSession.setActionHandler('seekforward', + this._skipReverseByInterval(new CustomEvent('skip', { 'detail': {'key': 'right'} })) + ); + navigator.mediaSession.setActionHandler('previoustrack', + this._skipReverseByInterval(new CustomEvent('skip', { 'detail': {'key': 'down'} })) + ); + navigator.mediaSession.setActionHandler('nexttrack', + this._skipReverseByInterval(new CustomEvent('skip', { 'detail': {'key': 'up'} })) + ); + } + }); + }, + // Play/Pause controls playPause: function(e){ if (!!e) e.preventDefault(); var player = this; if ( player.canBePlayed ) { - return player.isPlaying ? player.$.audio.pause() : player.$.audio.play(); + return player.isPlaying ? player.$.audio.pause() : _startPlaying(); } else if (player.preload === 'none') { // If player can't be played, because audio wasn't pre-loaded // due to the preload="none" property set, // load the audio file at this point and start playing it immediately player.$.audio.load(); - player.$.audio.play(); + _startPlaying(); } }, @@ -405,7 +429,7 @@ if (!!e) e.preventDefault(); var player = this; player.$.audio.currentTime = 0; - if ( !player.isPlaying ) player.$.audio.play(); + if ( !player.isPlaying ) _startPlaying(); }, @@ -426,7 +450,7 @@ // If player has auto-play attribute set, // it ignores preload="none" property and starts playing on load. // This behavior corresponds to the native audio element behavior. - if (player.autoPlay) player.$.audio.play(); + if (player.autoPlay) _startPlaying(); }, @@ -464,7 +488,7 @@ } player._updatePlayPosition(newTime); - if (!player.isPlaying) player.$.audio.play(); + if (!player.isPlaying) _startPlaying(); }, @@ -543,7 +567,7 @@ if (player.canBePlayed) { player._updateProgressBar(e); - if (!player.isPlaying) player.$.audio.play(); + if (!player.isPlaying) _startPlaying(); // When preload="none" is being used, // player should first try to load the audio, @@ -552,7 +576,7 @@ player.$.audio.load(); player.$.audio.addEventListener('loadedmetadata', function() { player._updateProgressBar(e); - if (!player.isPlaying) player.$.audio.play(); + if (!player.isPlaying) _startPlaying(); }, false); } }, @@ -604,7 +628,7 @@ if (player.isPlaying) { player.$.audio.pause(); - player.$.audio.play(); + _startPlaying(); } }, @@ -630,4 +654,4 @@ } }); - \ No newline at end of file + From ab2352abe39748bf18b15d90288e4d2db1b51fdd Mon Sep 17 00:00:00 2001 From: Daniel Persson Date: Thu, 16 Mar 2017 11:38:25 +0100 Subject: [PATCH 6/9] Why always short. --- paper-audio-player.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/paper-audio-player.html b/paper-audio-player.html index 79f6d2c..dd04a3c 100755 --- a/paper-audio-player.html +++ b/paper-audio-player.html @@ -381,7 +381,7 @@ }, - _startPlaying() { + _startPlaying: function() { player.$.audio.play().then(_ => { if ('mediaSession' in navigator) { navigator.mediaSession.metadata = new MediaMetadata({ From 576e6a1576af59fe8cb1130829b20b6122944b19 Mon Sep 17 00:00:00 2001 From: Daniel Persson Date: Thu, 16 Mar 2017 11:44:03 +0100 Subject: [PATCH 7/9] Fail my bad. --- paper-audio-player.html | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/paper-audio-player.html b/paper-audio-player.html index dd04a3c..c38d8c4 100755 --- a/paper-audio-player.html +++ b/paper-audio-player.html @@ -412,13 +412,13 @@ var player = this; if ( player.canBePlayed ) { - return player.isPlaying ? player.$.audio.pause() : _startPlaying(); + return player.isPlaying ? player.$.audio.pause() : player._startPlaying(); } else if (player.preload === 'none') { // If player can't be played, because audio wasn't pre-loaded // due to the preload="none" property set, // load the audio file at this point and start playing it immediately player.$.audio.load(); - _startPlaying(); + player._startPlaying(); } }, @@ -429,7 +429,7 @@ if (!!e) e.preventDefault(); var player = this; player.$.audio.currentTime = 0; - if ( !player.isPlaying ) _startPlaying(); + if ( !player.isPlaying ) player._startPlaying(); }, @@ -450,7 +450,7 @@ // If player has auto-play attribute set, // it ignores preload="none" property and starts playing on load. // This behavior corresponds to the native audio element behavior. - if (player.autoPlay) _startPlaying(); + if (player.autoPlay) player._startPlaying(); }, @@ -488,7 +488,7 @@ } player._updatePlayPosition(newTime); - if (!player.isPlaying) _startPlaying(); + if (!player.isPlaying) player._startPlaying(); }, @@ -567,7 +567,7 @@ if (player.canBePlayed) { player._updateProgressBar(e); - if (!player.isPlaying) _startPlaying(); + if (!player.isPlaying) player._startPlaying(); // When preload="none" is being used, // player should first try to load the audio, @@ -576,7 +576,7 @@ player.$.audio.load(); player.$.audio.addEventListener('loadedmetadata', function() { player._updateProgressBar(e); - if (!player.isPlaying) _startPlaying(); + if (!player.isPlaying) player._startPlaying(); }, false); } }, @@ -628,7 +628,7 @@ if (player.isPlaying) { player.$.audio.pause(); - _startPlaying(); + player._startPlaying(); } }, From 0de941864ea27eb9acc714bb66889ad2bf6abc2e Mon Sep 17 00:00:00 2001 From: Daniel Persson Date: Thu, 23 Mar 2017 06:55:33 +0100 Subject: [PATCH 8/9] Small fixes during debugging. --- paper-audio-player.html | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/paper-audio-player.html b/paper-audio-player.html index c38d8c4..a34ab4a 100755 --- a/paper-audio-player.html +++ b/paper-audio-player.html @@ -382,26 +382,32 @@ _startPlaying: function() { + var player = this; + player.$.audio.play().then(_ => { if ('mediaSession' in navigator) { navigator.mediaSession.metadata = new MediaMetadata({ - title: this.title, + title: player.title, }); - navigator.mediaSession.setActionHandler('play', this.playPause()); - navigator.mediaSession.setActionHandler('pause', this.pause()); - navigator.mediaSession.setActionHandler('seekbackward', - this._skipReverseByInterval(new CustomEvent('skip', { 'detail': {'key': 'left'} })) - ); - navigator.mediaSession.setActionHandler('seekforward', - this._skipReverseByInterval(new CustomEvent('skip', { 'detail': {'key': 'right'} })) - ); - navigator.mediaSession.setActionHandler('previoustrack', - this._skipReverseByInterval(new CustomEvent('skip', { 'detail': {'key': 'down'} })) - ); - navigator.mediaSession.setActionHandler('nexttrack', - this._skipReverseByInterval(new CustomEvent('skip', { 'detail': {'key': 'up'} })) - ); + navigator.mediaSession.setActionHandler('play', function() { + player.playPause() + }); + navigator.mediaSession.setActionHandler('pause', function() { + player.pause() + }); + navigator.mediaSession.setActionHandler('seekbackward', function() { + player._skipReverseByInterval(new CustomEvent('skip', { 'detail': {'key': 'left'} })); + }); + navigator.mediaSession.setActionHandler('seekforward', function() { + player._skipReverseByInterval(new CustomEvent('skip', { 'detail': {'key': 'right'} })); + }); + navigator.mediaSession.setActionHandler('previoustrack', function() { + player._skipReverseByInterval(new CustomEvent('skip', { 'detail': {'key': 'down'} })); + }); + navigator.mediaSession.setActionHandler('nexttrack', function() { + player._skipReverseByInterval(new CustomEvent('skip', { 'detail': {'key': 'up'} })); + }); } }); }, From b5a60ab6a7fe5d7f24b41c15ce4bf28c8bc6332c Mon Sep 17 00:00:00 2001 From: Daniel Persson Date: Thu, 23 Mar 2017 13:50:26 +0100 Subject: [PATCH 9/9] Remove newer javascript version requirement. --- paper-audio-player.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/paper-audio-player.html b/paper-audio-player.html index a34ab4a..70ca213 100755 --- a/paper-audio-player.html +++ b/paper-audio-player.html @@ -384,7 +384,7 @@ _startPlaying: function() { var player = this; - player.$.audio.play().then(_ => { + player.$.audio.play().then(function() { if ('mediaSession' in navigator) { navigator.mediaSession.metadata = new MediaMetadata({ title: player.title,