mirror of
https://github.com/pierre42100/ComunicWeb
synced 2025-09-19 05:49:07 +00:00
Created song player class
This commit is contained in:
34
assets/js/common/songPlayer.js
Normal file
34
assets/js/common/songPlayer.js
Normal 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();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user