this.playlist = this.options.playlist;
this.buildPlaylistControls();
this.loadPlaylist();
- this.options.onLoad(this);
this._update();
+ this.options.onLoad(this);
},
_setOption: function( key, value ) {
this.options.onUpdate(this);
return this.playlist;
},
+ _reset: function() {
+ this.isActive =false;
+ this.stopSounds();
+ this.playlistContainer.find('*').remove();
+ this._update();
+ },
savePlaylist: function(){
- localStorage['playlist'] = JSON.stringify(this.playlist, null, '\t');
+ var JSONPlaylist = JSON.stringify(this.playlist, null, '\t');
+ if (localStorage !== null && localStorage !== undefined) {
+ localStorage['playlist'] = JSON.stringify(this.playlist, null, '\t');
+ }
},
loadPlaylist: function(){
- this.playlist = localStorage['playlist']?JSON.parse(localStorage['playlist']):this.playlist;
+ if (localStorage !== null && localStorage !== undefined) {
+ this.playlist = localStorage['playlist']?JSON.parse(localStorage['playlist']):this.playlist;
+ }
$.each(this.playlist,function(k,v){
thePlaylist.playlistContainer.append(thePlaylist._htmlifyJsonSound(v));
});
var sound = {
source :{},
title: audio.attr('title'),
- id:audio.attr('id'),
+ sound_id:audio.data('sound-id'),
+ url:audio.attr('data-url'),
focus:audio.attr('data-player-focus')
};
audio.children('source').each(function(){
// Transform JSON sound object to HTML container for playlist.
_htmlifyJsonSound: function(sound) {
var container = $('<li>');
- var audio = $('<audio>',this.options.html5audioOptions).hide();
+ var audio = $('<audio>',this.options.html5audioOptions)
+ .attr('title',sound.title).hide()
+ .attr('data-sound-id', sound.sound_id)
+ .attr('data-url',sound.url);
+ var audio_str = sound.sound_id + ': ' + sound.title;
$.each(sound.source,function(k,v){
var source = $('<source>',{src:v,type:k});
audio.append(source);
});
- audio.attr('title',sound.title)
- .attr('data-origin',sound.id)
- .on('play',function(){
+ audio.on('play',function(e){
+ if (e.originalEvent === undefined) {
+ return;
+ }
+ if (typeof (_paq) == 'object') {
+ _paq.push(['trackEvent', 'Audio', 'Play', audio_str]);
+ }
thePlaylist.setFocus(container);
container.addClass('playing');
playpause.addClass('icon-pause').removeClass('icon-play');
thePlaylist.controlButtons['playpause'].removeClass('icon-play').addClass('icon-pause');
thePlaylist.afterPlay();
- }).on('pause',function(){
+ var sound_id = $(e.target).data('sound-id');
+ $(document).trigger('panik:play', {'sound_id': sound_id});
+ }).on('pause',function(e){
$(this).removeClass('playing');
playpause.addClass('icon-play').removeClass('icon-pause');
+ var sound_id = $(e.target).data('sound-id');
+ $(document).trigger('panik:pause', {'sound_id': sound_id});
thePlaylist.controlButtons['playpause'].removeClass('icon-pause').addClass('icon-play');
- }).on('stop',function(){
+ }).on('stop',function(event){
$(this).trigger('pause');
- $(this)[0].currentTime = 0;
- }).on("ended", function(){
+ if($(this)[0].currentTime){$(this)[0].currentTime = 0;}
+ }).on("ended", function(e){
+ if (typeof (_paq) == 'object') {
+ _paq.push(['trackEvent', 'Audio', 'End', audio_str]);
+ }
thePlaylist.playNext();
}).on('beforePause',function(){
return this;
}).on('beforePlay',function(){
thePlaylist.pauseSounds();
return this;
+ }).on('timeupdate', function(event) {
+ var position = 1.0 * event.target.currentTime / event.target.duration;
+ var sound_id = $(event.target).data('sound-id');
+ $(document).trigger('panik:timeupdate',
+ {'sound_id': sound_id, 'position': position});
});
- var controls = $('<span>',{class:'soundControls controls'});
- var html5 = $('<button>',{class:'icon-html5',click:function(){
- audio.toggle();
- }}).hide();
- var remove = $('<button>',{class:'icon-remove',click:function(){
+ var controls = $('<span>',{'class':'soundControls controls'});
+ var link = $('<a>',{href:sound.url,'class':'button icon-external-link'});
+ var remove = $('<button>',{title:"Remove from list",'class':'icon-remove',click:function(){
+ audio.trigger('stop');
container.remove();
thePlaylist._update();
}});
- var stop = $('<button>',{class:'icon-stop',click:function(){
+ var stop = $('<button>',{title:"Stop",'class':'icon-stop',click:function(){
audio.trigger('stop');
- }});
- var playpause = $('<button>',{class:'icon-play',click:function(){
+ }}).hide();
+ var playpause = $('<button>',{title:"Play/Pause",'class':'icon-play',click:function(){
if (audio[0].paused == false) { audio.trigger('pause');
} else {
audio.trigger('beforePlay').trigger('play');
}
}});
- controls.append(playpause).append(stop).append(remove).append(html5);
- var title = $('<span>',{class:"button title",html:sound.title,click:function(){
- playpause.trigger('click');
- return false;
- }});
+ controls.append(playpause).append(stop).append(remove);
+ var title = $('<a>',{title:"More information",href:sound.url,'class':"button title",html:sound.title});
container.append(controls).append(title).append(audio);
if(sound.focus){thePlaylist.setFocus(container);}
return container;
},
// Create a public method.
registerAudio: function(audio,success) {
- var htmlAudio = this._htmlifyJsonSound(this.jsonifyAudio(audio));
+ var sound_id = audio.data('sound-id');
+ if (this.playlistContainer.find('[data-sound-id=' + sound_id + ']').length) {
+ /* already in playlist */
+ return;
+ }
+ var audioObj = this.jsonifyAudio(audio);
+ var htmlAudio = this._htmlifyJsonSound(audioObj);
this.playlistContainer.append(htmlAudio);
this.isLastAdd = htmlAudio;
if(!this.isActive){this.setFocus(this.isLastAdd);}
this._update();
},
// Play next sound
+ bindControl: function(control,audio,element,options) {
+ element.addClass('loading');
+ audioID = audio.data('souce-id');
+ //TODO for controls in page content
+ },
+ // Play next sound
registerControl: function(name,options) {
this.controlButtons[name] = $('<button>',options);
this.controlContainer.append(this.controlButtons[name]);
},
// Build controls
buildPlaylistControls: function() {
- this.controls = $('<div>',{class:'playlistControls controls'});
- this.registerControl('toggleList',{class:"icon-list hidden",click: function(){
+ this.controlContainer.empty();
+ /*
+ this.registerControl('toggleList',{class:"icon-list",click: function(){
thePlaylist.playlistContainer.toggle();
}});
this.registerControl('clearList',{class:"icon-trash",click: function(){
thePlaylist.playlistContainer.empty();
thePlaylist._update();
}});
- this.registerControl('previous',{class:"icon-step-backward",click:function(){
+ */
+ this.registerControl('previous',{'class':"icon-step-backward",click:function(){
thePlaylist.playPrevious();
}});
- this.registerControl('stop',{class:"icon-stop",click: function(){
+ this.registerControl('stop',{'class':"icon-stop",click: function(){
thePlaylist.stopSounds();
}});
- this.registerControl('playpause',{class:"icon-play",click: function(){
+ this.registerControl('playpause',{'class':"icon-play playPause",click: function(){
thePlaylist.playPauseList();
}});
- this.registerControl('next',{class:"icon-step-forward",click: function(){
+ this.registerControl('next',{'class':"icon-step-forward",click: function(){
thePlaylist.playNext();
}});
return true;
this.stopSounds();
},
// Play next sound
+ getActive: function() {
+ if(!this.isActive){
+ this.isActive = this.playlistContainer.children('li').first();
+ }
+ return this.isActive;
+ },
+ playSoundId: function(sound_id) {
+ this.playlistContainer.find('audio[data-sound-id="' + sound_id + '"]'
+ ).trigger('beforePlay').trigger('play');
+ },
+ // Play next sound
playPauseList: function() {
if(this.controlButtons['playpause'].hasClass('icon-play')){
- if(this.isActive){
- this.isActive.find('audio').trigger('beforePlay').trigger('play');
- }else{
- this.playlistContainer.children('li').first().find('audio').trigger('beforePlay').trigger('play');
- }
+ this.getActive().find('audio').trigger('beforePlay').trigger('play');
}else{
- this.isActive.find('audio').trigger('pause');
+ this.getActive().find('audio').trigger('pause');
}
return true;
},
// Play next sound
playPrevious: function() {
- this.isActive.prev().find('audio').trigger('beforePlay').trigger('play');
+ this.getActive().prev().find('audio').trigger('beforePlay').trigger('play');
return true;
},
// Play next sound
playNext: function() {
- this.isActive.next().find('audio').trigger('beforePlay').trigger('play');
+ this.getActive().next().find('audio').trigger('beforePlay').trigger('play');
+ return true;
+ },
+ // Play next sound
+ playFirst: function() {
+ this.playlistContainer.find('audio').first().trigger('beforePlay').trigger('play');
+ return true;
+ },
+ // Play next sound
+ playLast: function() {
+ this.playlistContainer.find('audio').last().trigger('beforePlay').trigger('play');
return true;
},
// Pause all sounds.
- pauseSounds: function(selector) {
+ pauseSounds: function() {
this.playlistContainer.find('audio').each(function(){$(this).trigger('pause');});
},
// stop all sounds.
- stopSounds: function(rewind) {
- this.playlistContainer.find('audio').each(function(){
- $(this).trigger('stop');
- });
- return true;
+ stopSounds: function() {
+ this.playlistContainer.find('audio').each(function(){$(this).trigger('stop');});
},
});
})(jQuery);