Skip to content

Commit 6c4bf7d

Browse files
committed
Add autoplay option upon init configuration.
1 parent 33cf8d7 commit 6c4bf7d

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

example-init.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
*/
44
player.init({
55
loop: 'all', // 'none', 'one', 'all'. Default: 'none'.
6+
volume: 50, // 1 to 100.
7+
autoplay: false,
68
songs: [
79
//{url: 'https://upload.wikimedia.org/wikipedia/en/4/45/ACDC_-_Back_In_Black-sample', name: 'Black in Black'},
810
{url: 'songs/one', name: 'Amberdawn'},

player.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,16 @@ var player = (function () {
105105
//
106106
var sourceOgg = createNode('source');
107107
sourceOgg.setAttribute('id', 'oggPath');
108-
sourceMp3.setAttribute('type', 'audio/ogg');
108+
sourceOgg.setAttribute('type', 'audio/ogg');
109109
sourceOgg.setAttribute('src', arrSongs[index].url + '.ogg');
110110
_self.dnAudio.appendChild(sourceOgg);
111111

112+
// The audio tag iteself is built only once. When the current song
113+
// changes, only its audio url changes, but we do not recreate the audio
114+
// tag. That means autoplay only works on page load and it doesn't interfere
115+
// with changing songs through the playlist later.
116+
_self.dnAudio.autoplay = _self.config.autoplay;
117+
112118
_self.currentSongIndex = parseInt(index, 10);
113119
};
114120

@@ -551,6 +557,7 @@ var player = (function () {
551557

552558
config.volume = config.volume || 80;
553559
config.volume = config.volume / 100;
560+
config.autoplay = config.autoplay || false;
554561

555562
_self.config = config;
556563
}

0 commit comments

Comments
 (0)