aboutsummaryrefslogtreecommitdiffstats
path: root/src/client/Main.hx
diff options
context:
space:
mode:
authorRblSb <msrblsb@gmail.com>2025-01-12 19:35:56 +0300
committerRblSb <msrblsb@gmail.com>2025-01-12 22:35:22 +0300
commitf84fdc40ba817b6a2d907484b1e1500197ceeafe (patch)
tree73a5b81e082d0ac1741c24742db12e6c2bd54249 /src/client/Main.hx
parent25b7ecb45d43018235c6a8eb5b4ce833f2dec668 (diff)
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).
Diffstat (limited to 'src/client/Main.hx')
-rw-r--r--src/client/Main.hx29
1 files changed, 27 insertions, 2 deletions
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<Timer>;
+ 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;
}
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage