repo: janusweb action: commit revision: path_from: revision_from: dde0c0eaecf268b954eec19b9a6400190288dad3: path_to: revision_to:
commit dde0c0eaecf268b954eec19b9a6400190288dad3 Author: James BaicoianuDate: Sat Jun 13 00:15:15 2020 -0700 Handle audio autoplay for videos diff --git a/scripts/video.js b/scripts/video.js
--- a/scripts/video.js
+++ b/scripts/video.js
@@ -97,6 +97,7 @@ elation.require(['janusweb.janusbase'], function() {
this.soundobj = new THREE.PositionalAudio(listener);
this.objects['3d'].add(this.soundobj);
+ this.soundobj.isPlaying = true;
//this.panner = this.context.createPanner();
//this.panner.connect(ctx.destination);
@@ -153,8 +154,16 @@ elation.require(['janusweb.janusbase'], function() {
return (video && video.currentTime > 0 && !video.paused && !video.ended);
}
this.play = function() {
- if (!this.isPlaying()) {
- this.video.play();
+ if (!this.engine.systems.sound.canPlaySound) {
+ if (!this.playDelayed) {
+ this.playDelayed = true;
+ elation.events.add(this.engine.systems.sound, 'sound_enabled', (ev) => { this.play(); });
+ this.dispatchEvent({type: 'sound_delayed'});
+ }
+ } else {
+ if (!this.isPlaying()) {
+ this.video.play();
+ }
}
}
this.pause = function() {
-----END OF PAGE-----