我正在使用“angualr-youtube-embed”指令将 youtube 播放器嵌入到我的 Angular Web 应用程序中。因为我必须识别播放和暂停以及音量变化事件。要收听播放和暂停事件,我使用下面给出的代码。
$scope.$on('youtube.player.playing', function ($event, player) {
// to do functions when the video is playing.
});
$scope.$on('youtube.player.paused', function ($event, player) {
// to do functions when the video is paused.
});
现在我的要求是,我想在 youtube 播放器中改变音量的同时做一些工作,我需要识别那个音量改变事件。但我不知道如何听 youtube 播放器中的音量变化。我该如何解决这个问题?
提前致谢。
最佳答案
以防万一有人有同样的问题,here是我的完整答案。
今天的代码如下:
setInterval(this.getChangedVolume, 250)
getChangedVolume () {
let currentYoutubeVolume = this.player.getVolume()
// Do some things, for example (will show Promise):
// console.log(currentYoutubeVolume)
// YouTube returns Promise, but we need actual data, so:
// Promise.resolve(currentYoutubeVolume).then(data => { this.volumeLv = data })
}
关于javascript - 如何识别 youtube 播放器中的音量变化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30068869/