From 4d51b5d61f0012a48b9f37c1059aeb6700705381 Mon Sep 17 00:00:00 2001 From: George Hu Date: Sun, 10 Mar 2024 22:37:17 +0800 Subject: [PATCH] audio: workaroud for yt policy --- src/utils/base.js | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/utils/base.js b/src/utils/base.js index 7dc47c3..f3a3e4c 100644 --- a/src/utils/base.js +++ b/src/utils/base.js @@ -53,14 +53,36 @@ function withProgress(resp, totalSize = null) { })); } +let init = false async function loadMusicFromYT(api) { const player = videojs.getPlayer("rawPlayer") player.src({ "type": "video/youtube", "src": api.musicYtURL }) - await player.play() - player.pause() + + // workaroud for yt policy + if(!init) { + const savedTime = api["currentTime"] + const savedVolume = api["volume"] + await player.play() + player.volume(0.0); + player.on('play', async () => { + if(!init) { + player.pause() + await player.play() + player.pause() + player.volume(savedVolume); + } + }) + player.on('pause', () => { + if(!init) { + player.currentTime(savedTime); + init = true + } + }) + } + api.musicName = player.tech(true).ytPlayer.videoTitle api.musicURL = ""; }