description: '',
state: 'stop', // state var: to state play or pause glyphicon
playing: '', // playing var: used to know if an audio is already playing or not
+ audio: new Audio(),
addPlaylist: function(name, id){
this.playlists.push({
},
loadAudio: function(resElem){
- var audio = new Audio();
- //For old browsers that do not support mp3 files
- /*audio.onerror = function(){
- this.src = this.src.replace("mp3", "ogg");
- this.play();
- };*/
- audio.src = resElem;
- audio.play();
+ this.audio.src = resElem;
+ this.audio.play();
},
- stopAudio: function(resElem){
- var audio = new Audio();
- audio.src = resElem;
- audio.pause();
+ stopAudio: function(){
+ this.audio.pause();
},
changeGlyph: function(resElem){
this.state = 'play';
document.getElementById(resElem).setAttribute("class", "glyphicon glyphicon-pause");
playlistUtils.loadAudio(resElem);
+ this.playing = resElem;
}
else if(this.state === 'play'){
this.state = 'stop';
document.getElementById(resElem).setAttribute("class", "glyphicon glyphicon-play");
- playlistUtils.stopAudio(resElem);
+ playlistUtils.stopAudio();
+ this.playing = '';
}
- this.playing = resElem;
}
else{
- playlistUtils.stopAudio(this.playing);
+ playlistUtils.stopAudio();
this.state = 'stop';
document.getElementById(this.playing).setAttribute("class", "glyphicon glyphicon-play");
this.playing = '';