Created song player class

This commit is contained in:
Pierre HUBERT 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();
}
}

View File

@ -18,24 +18,13 @@ ComunicWeb.components.notifications.song = {
//Create song element if required
if(this.songElem == null){
this.songElem = createElem2({
type: "audio"
});
createElem2({
type: "source",
appendTo: this.songElem,
src: ComunicWeb.__config.assetsURL + "audio/notif_song.mp3"
});
createElem2({
type: "source",
appendTo: this.songElem,
src: ComunicWeb.__config.assetsURL + "audio/notif_song.ogg"
});
this.songElem = new SongPlayer([
ComunicWeb.__config.assetsURL + "audio/notif_song.mp3",
ComunicWeb.__config.assetsURL + "audio/notif_song.ogg"
]);
}
//Play song
this.songElem.play();
this.songElem.playOnce();
}
}

View File

@ -320,6 +320,7 @@ class Dev {
"js/common/formChecker.js",
"js/common/date.js",
"js/common/system.js",
"js/common/songPlayer.js",
//Languages
"js/langs/en.inc.js",