Skip to content

Commit bab60d5

Browse files
authored
Merge pull request #4 from arianahl/fix/looping-tracks
Add an event listener to replay the audio file once it ends
2 parents 7b2a2db + 5661a00 commit bab60d5

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/player.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,11 @@ let playerPageFn = (id) => {
6969
audioFile.src = '../assets/' + id + '.mp3';
7070
}
7171
audioFile.play();
72-
audioFile.loop = true;
72+
// The loop property is not always supported so add an event listener instead
73+
audioFile.addEventListener('ended', function() {
74+
this.currentTime = 0;
75+
this.play();
76+
}, false);
7377
$pause.style.visibility = 'visible';
7478
$play.style.visibility = 'hidden';
7579

0 commit comments

Comments
 (0)