I am using 'angualr-youtube-embed' directive to embed youtube player in my angular web app. In that I have to identify play and pause and volume change events. To listen play and pause events I am using the below given code.
我使用'angualr-youtube-embed'指令将youtube播放器嵌入我的角度网络应用程序中。在那里我必须识别播放和暂停以及音量变化事件。要收听播放和暂停事件,我使用下面给出的代码。
$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.
});
Now my requirement is, I want to do some works while changing volume in youtube player, I need to identify that volume change event. But I have no idea about how to listen the volume change in youtube player. How can I solve this issue?
现在我的要求是,我想在改变youtube播放器的音量时做一些工作,我需要确定音量改变事件。但我不知道如何在youtube播放器中收听音量变化。我该如何解决这个问题?
Thanks in advance.
提前致谢。
2 个解决方案
#1
player.getVolume():Number
Returns the player's current volume, an integer between 0 and 100. Note that getVolume() will return the volume even if the player is muted.
返回播放器的当前音量,0到100之间的整数。请注意,即使播放器静音,getVolume()也会返回音量。
For more Detail check this: YouTube Player Controls
有关详细信息,请查看此处:YouTube播放器控件
#2
Just in case if anyone has the same question, here is my full answer.
如果有人有同样的问题,这是我的完整答案。
For today the code looks like:
对于今天的代码看起来像:
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 })
}
#1
player.getVolume():Number
Returns the player's current volume, an integer between 0 and 100. Note that getVolume() will return the volume even if the player is muted.
返回播放器的当前音量,0到100之间的整数。请注意,即使播放器静音,getVolume()也会返回音量。
For more Detail check this: YouTube Player Controls
有关详细信息,请查看此处:YouTube播放器控件
#2
Just in case if anyone has the same question, here is my full answer.
如果有人有同样的问题,这是我的完整答案。
For today the code looks like:
对于今天的代码看起来像:
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 })
}