Переглянути джерело

fix initial video autoplay not working in android

Hakim El Hattab 2 тижнів тому
батько
коміт
1427059378

Різницю між файлами не показано, бо вона завелика
+ 0 - 0
dist/reveal.esm.js


Різницю між файлами не показано, бо вона завелика
+ 0 - 0
dist/reveal.esm.js.map


Різницю між файлами не показано, бо вона завелика
+ 0 - 0
dist/reveal.js


Різницю між файлами не показано, бо вона завелика
+ 0 - 0
dist/reveal.js.map


+ 2 - 2
examples/media.html

@@ -33,10 +33,10 @@
 
 				<section>
 					<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 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>
 				</section>
 

+ 31 - 2
js/controllers/slidecontent.js

@@ -9,6 +9,8 @@ import fitty from 'fitty';
  */
 export default class SlideContent {
 
+	allowedToPlay = true;
+
 	constructor( Reveal ) {
 
 		this.Reveal = Reveal;
@@ -332,7 +334,11 @@ export default class SlideContent {
 						// If autoplay does not work, ensure that the controls are visible so
 						// that the viewer can start the media on their own
 						if( promise && typeof promise.catch === 'function' && el.controls === false ) {
-							promise.catch( () => {
+							promise
+							.then( () => {
+								this.allowedToPlay = true;
+							})
+							.catch( () => {
 								el.controls = true;
 
 								// 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
 			if( event.target.paused || event.target.ended ) {
 				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;
+
+	}
+
 }

+ 8 - 0
js/controllers/touch.js

@@ -216,6 +216,14 @@ export default class Touch {
 	 */
 	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;
 
 	}

Деякі файли не було показано, через те що забагато файлів було змінено