mirror of
https://github.com/pierre42100/ComunicWeb
synced 2024-11-23 04:29:21 +00:00
Created song player class
This commit is contained in:
parent
8c6e04abd0
commit
289a66e55b
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();
|
||||||
|
}
|
||||||
|
}
|
@ -18,24 +18,13 @@ ComunicWeb.components.notifications.song = {
|
|||||||
|
|
||||||
//Create song element if required
|
//Create song element if required
|
||||||
if(this.songElem == null){
|
if(this.songElem == null){
|
||||||
this.songElem = createElem2({
|
this.songElem = new SongPlayer([
|
||||||
type: "audio"
|
ComunicWeb.__config.assetsURL + "audio/notif_song.mp3",
|
||||||
});
|
ComunicWeb.__config.assetsURL + "audio/notif_song.ogg"
|
||||||
|
]);
|
||||||
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"
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Play song
|
//Play song
|
||||||
this.songElem.play();
|
this.songElem.playOnce();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -320,6 +320,7 @@ class Dev {
|
|||||||
"js/common/formChecker.js",
|
"js/common/formChecker.js",
|
||||||
"js/common/date.js",
|
"js/common/date.js",
|
||||||
"js/common/system.js",
|
"js/common/system.js",
|
||||||
|
"js/common/songPlayer.js",
|
||||||
|
|
||||||
//Languages
|
//Languages
|
||||||
"js/langs/en.inc.js",
|
"js/langs/en.inc.js",
|
||||||
|
Loading…
Reference in New Issue
Block a user