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/players/Youtube.hx | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 'src/client/players/Youtube.hx') diff --git a/src/client/players/Youtube.hx b/src/client/players/Youtube.hx index cde2ef8..3ad9030 100644 --- a/src/client/players/Youtube.hx +++ b/src/client/players/Youtube.hx @@ -86,10 +86,11 @@ class Youtube implements IPlayer { final duration = convertTime(duration); // duration is PT0S for streams if (duration == 0) { + final mute = main.isAutoplayAllowed() ? "" : "&mute=1"; callback({ duration: 99 * 60 * 60, title: title, - url: '', isIframe: true @@ -211,13 +212,14 @@ class Youtube implements IPlayer { videoId: extractVideoId(item.url), playerVars: { autoplay: 1, + // play videos inline instead of fullscreen on iOS playsinline: 1, - modestbranding: 1, + // related videos only from same channel rel: 0, - showinfo: 0 }, events: { onReady: e -> { + if (!main.isAutoplayAllowed()) e.target.mute(); isLoaded = true; youtube.pauseVideo(); }, @@ -271,6 +273,7 @@ class Youtube implements IPlayer { info.formats ??= []; info.adaptiveFormats ??= []; final formats = info.adaptiveFormats.concat(info.formats); + trace(formats); final qPriority = [1080, 720, 480, 360, 240]; for (q in qPriority) { final quality = '${q}p'; @@ -304,6 +307,10 @@ class Youtube implements IPlayer { youtube.pauseVideo(); } + public function isPaused():Bool { + return youtube.getPlayerState() == PAUSED; + } + public function getTime():Float { return youtube.getCurrentTime(); } @@ -319,4 +326,17 @@ class Youtube implements IPlayer { public function setPlaybackRate(rate:Float):Void { youtube.setPlaybackRate(rate); } + + public function getVolume():Float { + if (youtube.isMuted()) return 0; + return youtube.getVolume() / 100; + } + + public function setVolume(volume:Float):Void { + youtube.setVolume(Std.int(volume * 100)); + } + + public function unmute():Void { + youtube.unMute(); + } } -- cgit v1.2.3