Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add toggleAutoAdvance to API #183

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 31 additions & 2 deletions audio-slideshow/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ window.RevealAudioSlideshow = window.RevealAudioSlideshow || {
id: 'RevealAudioSlideshow',
init: function(deck) {
initAudioSlideshow(deck);
}
},
toggleAutoAdvance: function() { return toggleAutoAdvance(); },
};

const initAudioSlideshow = function(Reveal){
Expand All @@ -44,6 +45,7 @@ const initAudioSlideshow = function(Reveal){
var currentAudio = null;
var previousAudio = null;
var timer = null;
var defaultAdvance = 0;

Reveal.addEventListener( 'fragmentshown', function( event ) {
if ( timer ) { clearTimeout( timer ); timer = null; }
Expand Down Expand Up @@ -104,6 +106,25 @@ const initAudioSlideshow = function(Reveal){
}
} );

function toggleAutoAdvance() {
if ( autoplay ) {
if ( currentAudio ) {
if ( timer ) { clearTimeout( timer ); timer = null; }
currentAudio.pause();
}
autoplay = false;
advance = -1;
}
else {
if ( currentAudio && currentAudio.paused ) currentAudio.play();
autoplay = true;
advance = defaultAdvance;
}
return autoplay;
}

Reveal.addKeyBinding( { keyCode: 160, key: '^', description: 'Toggle audio autoadvance' }, toggleAutoAdvance );

function selectAudio( previousAudio ) {
if ( currentAudio ) {
currentAudio.pause();
Expand Down Expand Up @@ -156,7 +177,11 @@ const initAudioSlideshow = function(Reveal){
currentPlaybackRate = config.defaultPlaybackRate;
}

if ( config.advance != null ) advance = config.advance;
if ( config.advance != null ) {
advance = config.advance;
defaultAdvance = config.advance;
}

if ( config.autoplay != null ) autoplay = config.autoplay;
if ( config.playerOpacity != null ) playerOpacity = config.playerOpacity;
if ( config.playerStyle != null ) playerStyle = config.playerStyle;
Expand Down Expand Up @@ -466,6 +491,10 @@ const initAudioSlideshow = function(Reveal){
function getPlaybackRate() {
return currentPlaybackRate;
}

this.toggleAutoAdvance = toggleAutoAdvance;

return this;
};

/*****************************************************************
Expand Down