diff --git a/assets/js/common/songPlayer.js b/assets/js/common/songPlayer.js new file mode 100644 index 00000000..2a99a888 --- /dev/null +++ b/assets/js/common/songPlayer.js @@ -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(); + } +} \ No newline at end of file diff --git a/assets/js/components/notifications/song.js b/assets/js/components/notifications/song.js index e79c160f..2a8f1c7e 100644 --- a/assets/js/components/notifications/song.js +++ b/assets/js/components/notifications/song.js @@ -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(); } } \ No newline at end of file diff --git a/system/config/dev.config.php b/system/config/dev.config.php index 002ae378..f02d6371 100644 --- a/system/config/dev.config.php +++ b/system/config/dev.config.php @@ -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",