Created song player class

This commit is contained in:
2019-01-26 15:26:49 +01:00
parent 8c6e04abd0
commit 289a66e55b
3 changed files with 40 additions and 16 deletions

View File

@@ -0,0 +1,34 @@
/**
* Song player
*
* @author Pierre HUBERT
*/
class SongPlayer {
/**
* Initialize a new SongPlayer instance
*
* @param {String[]} sources The list of sources to exploit for the song
*/
constructor(sources){
this.songElem = document.createElement("audio");
//Process the list of sources
for (var index = 0; index < sources.length; index++) {
var url = sources[index];
var source = document.createElement("source");
source.src = url;
this.songElem.appendChild(source);
}
}
/**
* Play audio just once
*/
playOnce(){
this.songElem.play();
}
}