Skip to content
Snippets Groups Projects
Commit 32736a79 authored by Hakim El Hattab's avatar Hakim El Hattab
Browse files

auto play/pause html5 media when entering/leaving slide (#388)

parent 18795c16
No related branches found
No related tags found
Loading
...@@ -1147,6 +1147,10 @@ var Reveal = (function(){ ...@@ -1147,6 +1147,10 @@ var Reveal = (function(){
} }
} }
// Handle embedded content
stopEmbeddedContent( previousSlide );
startEmbeddedContent( currentSlide );
updateControls(); updateControls();
updateProgress(); updateProgress();
...@@ -1419,6 +1423,38 @@ var Reveal = (function(){ ...@@ -1419,6 +1423,38 @@ var Reveal = (function(){
} }
/**
* Start playback of any embedded content inside of
* the targeted slide.
*/
function startEmbeddedContent( slide ) {
if( slide ) {
toArray( slide.querySelectorAll( 'video, audio' ) ).forEach( function( el ) {
if( !el.hasAttribute( 'data-ignore' ) ) {
el.play();
}
} );
}
}
/**
* Stop playback of any embedded content inside of
* the targeted slide.
*/
function stopEmbeddedContent( slide ) {
if( slide ) {
toArray( slide.querySelectorAll( 'video, audio' ) ).forEach( function( el ) {
if( !el.hasAttribute( 'data-ignore' ) ) {
el.pause();
}
} );
}
}
/** /**
* Reads the current URL (hash) and navigates accordingly. * Reads the current URL (hash) and navigates accordingly.
*/ */
......
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment