Skip to content

Commit

Permalink
audio: workaroud for yt policy
Browse files Browse the repository at this point in the history
  • Loading branch information
culdo committed Mar 10, 2024
1 parent 7ae5a53 commit 4d51b5d
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions src/utils/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "";
}
Expand Down

0 comments on commit 4d51b5d

Please sign in to comment.