How to detect volume change in YouTube player
I am using the "angualr-youtube-embed" directive to embed the YouTube player into my angular web app. In this, I have to identify the play, pause and volume change events. To listen for play and pause events, I am using the below code.
$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 work on volume change in YouTube player, I need to define this volume change event. But I dont know how to listen to volume change in YouTube player. How can I solve this problem?
Thanks in advance.
source to share
player.getVolume():Number
Returns the current volume of the player, an integer from 0 to 100. Note that getVolume () will return the volume even if the player is disabled.
Learn More Learn More: YouTube Player Controls
source to share
Just in case anyone has the same question, here is my complete answer.
As of today, the code looks like this:
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 })
}
source to share