Skip to content

Commit

Permalink
Merge pull request #4 from arianahl/fix/looping-tracks
Browse files Browse the repository at this point in the history
Add an event listener to replay the audio file once it ends
  • Loading branch information
siwalikm authored Oct 14, 2017
2 parents 7b2a2db + 5661a00 commit bab60d5
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,11 @@ let playerPageFn = (id) => {
audioFile.src = '../assets/' + id + '.mp3';
}
audioFile.play();
audioFile.loop = true;
// The loop property is not always supported so add an event listener instead
audioFile.addEventListener('ended', function() {
this.currentTime = 0;
this.play();
}, false);
$pause.style.visibility = 'visible';
$play.style.visibility = 'hidden';

Expand Down

0 comments on commit bab60d5

Please sign in to comment.