mirror of
https://github.com/hakimel/reveal.js.git
synced 2025-10-26 11:46:32 +01:00
fix initial video autoplay not working in android
This commit is contained in:
2
dist/reveal.esm.js
vendored
2
dist/reveal.esm.js
vendored
File diff suppressed because one or more lines are too long
2
dist/reveal.esm.js.map
vendored
2
dist/reveal.esm.js.map
vendored
File diff suppressed because one or more lines are too long
2
dist/reveal.js
vendored
2
dist/reveal.js
vendored
File diff suppressed because one or more lines are too long
2
dist/reveal.js.map
vendored
2
dist/reveal.js.map
vendored
File diff suppressed because one or more lines are too long
@@ -33,10 +33,10 @@
|
|||||||
|
|
||||||
<section>
|
<section>
|
||||||
<h2>Video</h2>
|
<h2>Video</h2>
|
||||||
<video src="http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4" data-autoplay></video>
|
<video src="https://static.slid.es/site/homepage/v1/homepage-video-editor.mp4" data-autoplay></video>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<section data-background-video="http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4">
|
<section data-background-video="https://static.slid.es/site/homepage/v1/homepage-video-editor.mp4">
|
||||||
<h2>Background Video</h2>
|
<h2>Background Video</h2>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ import fitty from 'fitty';
|
|||||||
*/
|
*/
|
||||||
export default class SlideContent {
|
export default class SlideContent {
|
||||||
|
|
||||||
|
allowedToPlay = true;
|
||||||
|
|
||||||
constructor( Reveal ) {
|
constructor( Reveal ) {
|
||||||
|
|
||||||
this.Reveal = Reveal;
|
this.Reveal = Reveal;
|
||||||
@@ -332,7 +334,11 @@ export default class SlideContent {
|
|||||||
// If autoplay does not work, ensure that the controls are visible so
|
// If autoplay does not work, ensure that the controls are visible so
|
||||||
// that the viewer can start the media on their own
|
// that the viewer can start the media on their own
|
||||||
if( promise && typeof promise.catch === 'function' && el.controls === false ) {
|
if( promise && typeof promise.catch === 'function' && el.controls === false ) {
|
||||||
promise.catch( () => {
|
promise
|
||||||
|
.then( () => {
|
||||||
|
this.allowedToPlay = true;
|
||||||
|
})
|
||||||
|
.catch( () => {
|
||||||
el.controls = true;
|
el.controls = true;
|
||||||
|
|
||||||
// Once the video does start playing, hide the controls again
|
// Once the video does start playing, hide the controls again
|
||||||
@@ -432,7 +438,19 @@ export default class SlideContent {
|
|||||||
// Don't restart if media is already playing
|
// Don't restart if media is already playing
|
||||||
if( event.target.paused || event.target.ended ) {
|
if( event.target.paused || event.target.ended ) {
|
||||||
event.target.currentTime = 0;
|
event.target.currentTime = 0;
|
||||||
event.target.play();
|
const promise = event.target.play();
|
||||||
|
|
||||||
|
if( promise && typeof promise.catch === 'function' ) {
|
||||||
|
promise
|
||||||
|
.then( () => {
|
||||||
|
this.allowedToPlay = true;
|
||||||
|
} )
|
||||||
|
.catch( ( error ) => {
|
||||||
|
if( error.name === 'NotAllowedError' ) {
|
||||||
|
this.allowedToPlay = false;
|
||||||
|
}
|
||||||
|
} );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -544,4 +562,15 @@ export default class SlideContent {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks whether media playback is blocked by the browser. This
|
||||||
|
* typically happens when media playback is initiated without a
|
||||||
|
* direct user interaction.
|
||||||
|
*/
|
||||||
|
isNotAllowedToPlay() {
|
||||||
|
|
||||||
|
return !this.allowedToPlay;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -216,6 +216,14 @@ export default class Touch {
|
|||||||
*/
|
*/
|
||||||
onTouchEnd( event ) {
|
onTouchEnd( event ) {
|
||||||
|
|
||||||
|
// Media playback is only allowed as a direct result of a
|
||||||
|
// user interaction. Some mobile devices do not consider a
|
||||||
|
// 'touchmove' to be a direct user action. If this is the
|
||||||
|
// case, we fall back to starting playback here instead.
|
||||||
|
if( this.touchCaptured && this.Reveal.slideContent.isNotAllowedToPlay() ) {
|
||||||
|
this.Reveal.startEmbeddedContent( this.Reveal.getCurrentSlide() );
|
||||||
|
}
|
||||||
|
|
||||||
this.touchCaptured = false;
|
this.touchCaptured = false;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user