|
@@ -92,12 +92,13 @@
|
|
|
this.hideTimeMS = 10000;
|
|
|
|
|
|
// history
|
|
|
- this.next_node = null;
|
|
|
this.currentHistoricIndex = null;
|
|
|
this.historic = [];
|
|
|
+ this.shuffle_is_active = false;
|
|
|
|
|
|
// object events
|
|
|
this.event_handlers = {
|
|
|
+ 'audio-play-next':[],
|
|
|
'audio-ended':[]
|
|
|
};
|
|
|
|
|
@@ -126,17 +127,21 @@
|
|
|
this.$next.on('click', this.playNext.bind(this));
|
|
|
// TODO: previous and next btns
|
|
|
},
|
|
|
- openDocument(node, next_node){
|
|
|
+ openDocument(node){
|
|
|
console.log('AudioPlayer openDocument', node);
|
|
|
this.historic.push(node);
|
|
|
this.currentHistoricIndex = this.historic.length-1;
|
|
|
- this.next_node = next_node || null;
|
|
|
- // TODO: emmit new playing doc (need for corpus map nowing that audio played from RandomPlayer)
|
|
|
+ // this.shuffle_mode = shuffle_mode || false;
|
|
|
this.launch();
|
|
|
},
|
|
|
launch(){
|
|
|
this.setSRC(this.historic[this.currentHistoricIndex].audio_url);
|
|
|
this.loadNode(this.historic[this.currentHistoricIndex].nid);
|
|
|
+ // emmit new playing doc (e.g.: corpus map nowing that audio played from RandomPlayer)
|
|
|
+ _$corpus_canvas.trigger({
|
|
|
+ 'type':'audio-node-opened',
|
|
|
+ 'id':this.historic[this.currentHistoricIndex].id
|
|
|
+ });
|
|
|
this.showHidePreviousBtn();
|
|
|
this.showHideNextBtn();
|
|
|
this.show();
|
|
@@ -173,14 +178,17 @@
|
|
|
this.audio.play();
|
|
|
},
|
|
|
playPrevious(){
|
|
|
- if(typeof this.historic[this.currentHistoricIndex-1] !== 'undefined'){
|
|
|
+ if(this.currentHistoricIndex > 0){
|
|
|
this.currentHistoricIndex -= 1;
|
|
|
this.launch();
|
|
|
}
|
|
|
},
|
|
|
playNext(){
|
|
|
- if(this.next_node){
|
|
|
- this.openDocument(this.next_node);
|
|
|
+ if(this.currentHistoricIndex < this.historic.length-1){
|
|
|
+ this.currentHistoricIndex += 1;
|
|
|
+ this.launch();
|
|
|
+ }else{
|
|
|
+ this.emmit('audio-play-next');
|
|
|
}
|
|
|
},
|
|
|
togglePlayPause(e){
|
|
@@ -190,6 +198,11 @@
|
|
|
this.audio.pause();
|
|
|
}
|
|
|
},
|
|
|
+ stop(){
|
|
|
+ this.audio.pause();
|
|
|
+ this.timeOutToHide();
|
|
|
+ },
|
|
|
+ // audio events
|
|
|
onPlaying(){
|
|
|
this.$container.addClass('is-playing');
|
|
|
},
|
|
@@ -211,10 +224,6 @@
|
|
|
this.emmit('audio-ended');
|
|
|
this.stop();
|
|
|
},
|
|
|
- stop(){
|
|
|
- this.$container.removeClass('is-playing');
|
|
|
- this.timeOutToHide();
|
|
|
- },
|
|
|
// cartel functions
|
|
|
loadNode(nid){
|
|
|
this.$cartel.addClass('loading');
|
|
@@ -236,15 +245,15 @@
|
|
|
show(){
|
|
|
this.$container.addClass('visible');
|
|
|
},
|
|
|
- showHidePreviousBtn(s){
|
|
|
- if(this.historic.length > 1){
|
|
|
+ showHidePreviousBtn(){
|
|
|
+ if(this.historic.length > 1 && this.currentHistoricIndex > 0){
|
|
|
this.$previous.addClass('is-active');
|
|
|
}else{
|
|
|
this.$previous.removeClass('is-active');
|
|
|
}
|
|
|
},
|
|
|
showHideNextBtn(){
|
|
|
- if(this.next_node){
|
|
|
+ if(this.currentHistoricIndex < this.historic.length-1 || this.shuffle_is_active){
|
|
|
this.$next.addClass('is-active');
|
|
|
}else{
|
|
|
this.$next.removeClass('is-active');
|
|
@@ -270,6 +279,7 @@
|
|
|
console.warn('AudioPlayer : event '+event_name+' does not exists');
|
|
|
}
|
|
|
this.event_handlers[event_name].push(handler);
|
|
|
+ return this;
|
|
|
},
|
|
|
emmit(event_name){
|
|
|
var handler;
|
|
@@ -473,7 +483,7 @@
|
|
|
function RandomPlayer(playlist){
|
|
|
this.active = false;
|
|
|
this.playlist = playlist;
|
|
|
- this.$btn = $('<a>').html('🔀').addClass('random-player-btn');
|
|
|
+ this.$btn = $('<a>').html('Shuffle').addClass('random-player-btn');
|
|
|
this.init()
|
|
|
};
|
|
|
RandomPlayer.prototype = {
|
|
@@ -482,13 +492,15 @@
|
|
|
$('<div>')
|
|
|
.addClass('block random-player')
|
|
|
.append(this.$btn)
|
|
|
- .insertAfter('#block-userlogin');
|
|
|
+ .insertAfter('#block-userlogin, #block-studiolinkblock');
|
|
|
|
|
|
// events
|
|
|
this.$btn.on('click', this.toggleActive.bind(this));
|
|
|
|
|
|
// attach an event on AudioPlayer
|
|
|
- _audio_player.on('audio-ended', this.onAudioPlayerEnded.bind(this));
|
|
|
+ _audio_player
|
|
|
+ .on('audio-ended', this.onAudioPlayerEnded.bind(this))
|
|
|
+ .on('audio-play-next', this.onAudioPlayNext.bind(this));
|
|
|
},
|
|
|
shuffle(){
|
|
|
var tempPLaylist = [];
|
|
@@ -504,30 +516,34 @@
|
|
|
},
|
|
|
toggleActive(e){
|
|
|
if (this.active) {
|
|
|
+ this.$btn.removeClass('is-active');
|
|
|
this.stop();
|
|
|
}else{
|
|
|
+ this.$btn.addClass('is-active');
|
|
|
this.shuffle();
|
|
|
- this.play();
|
|
|
+ this.start();
|
|
|
}
|
|
|
},
|
|
|
- play(){
|
|
|
- this.active = true;
|
|
|
+ start(){
|
|
|
+ this.active = _audio_player.shuffle_is_active = true;
|
|
|
this.next();
|
|
|
},
|
|
|
stop(){
|
|
|
- this.active = false;
|
|
|
+ this.active = _audio_player.shuffle_is_active = false;
|
|
|
// stop audio player
|
|
|
_audio_player.stop();
|
|
|
},
|
|
|
next(){
|
|
|
- if(this.shuffledPlaylist.length > 0)
|
|
|
+ if(this.active && this.shuffledPlaylist.length > 0)
|
|
|
_audio_player.openDocument(this.shuffledPlaylist.splice(0,1)[0]);
|
|
|
},
|
|
|
+ onAudioPlayNext(){
|
|
|
+ console.log('RandomPlayer : onAudioPlayNext()');
|
|
|
+ this.next();
|
|
|
+ },
|
|
|
onAudioPlayerEnded(){
|
|
|
console.log('RandomPlayer : onAudioPlayerEnded()');
|
|
|
- if(this.active){
|
|
|
- this.next();
|
|
|
- }
|
|
|
+ this.next();
|
|
|
}
|
|
|
};
|
|
|
|