From f84fdc40ba817b6a2d907484b1e1500197ceeafe Mon Sep 17 00:00:00 2001 From: RblSb Date: Sun, 12 Jan 2025 19:35:56 +0300 Subject: External audiotrack support This works as voice over if video also has audio, changing video volume to 0.3. Also improve autoplay by playing videos muted and unmute on first page click. There is no mute if you use Firefox and allow autoplay on page (navigator.getAutoplayPolicy check). --- src/client/Main.hx | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) (limited to 'src/client/Main.hx') diff --git a/src/client/Main.hx b/src/client/Main.hx index 2850c75..248e205 100644 --- a/src/client/Main.hx +++ b/src/client/Main.hx @@ -48,6 +48,7 @@ class Main { final player:Player; var onTimeGet:Timer; var onBlinkTab:Null; + var gotFirstPageInteraction = false; static function main():Void { new Main(); @@ -94,6 +95,17 @@ class Main { openWebSocket(); }); JsApi.init(this, player); + + document.addEventListener("click", onFirstInteraction); + } + + function onFirstInteraction():Void { + if (gotFirstPageInteraction) return; + if (!player.isVideoLoaded()) return; + gotFirstPageInteraction = true; + player.unmute(); + player.play(); + document.removeEventListener("click", onFirstInteraction); } function settingsPatcher(data:Any, version:Int):Any { @@ -319,6 +331,7 @@ class Main { duration: data.duration, isTemp: isTemp, subs: data.subs, + voiceOverTrack: data.voiceOverTrack, isIframe: data.isIframe == true }, atEnd: atEnd @@ -526,8 +539,11 @@ class Main { } if (player.isVideoLoaded()) forceSyncNextTick = false; if (player.getDuration() <= player.getTime() + synchThreshold) return; - if (!data.getTime.paused) player.play(); - else player.pause(); + if (player.isPaused()) { + if (!data.getTime.paused) player.play(); + } else { + if (data.getTime.paused) player.pause(); + } player.setPauseIndicator(!data.getTime.paused); if (Math.abs(time - newTime) < synchThreshold) return; // +0.5s for buffering @@ -1199,6 +1215,15 @@ class Main { return config.youtubePlaylistLimit; } + public function isAutoplayAllowed():Bool { + final navigator:{ + getAutoplayPolicy:(type:String) -> Bool + } = cast Browser.navigator; + if (navigator.getAutoplayPolicy != null) return + navigator.getAutoplayPolicy("mediaelement"); + return gotFirstPageInteraction; + } + public function isVerbose():Bool { return config.isVerbose; } -- cgit v1.2.3