3

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.

 $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?

Thanks in advance.

Anna
  • 973
  • 4
  • 13
  • 26

2 Answers2

1

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 })
  }
TitanFighter
  • 4,582
  • 3
  • 45
  • 73
0
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.

For more Detail check this: YouTube Player Controls

Jaimin Soni
  • 1,061
  • 1
  • 13
  • 29
  • 1
    Thanks for the comment. Actually I need to fire a function while the volume is changed, for that I have to identify that volume changed event. – Anna May 06 '15 at 06:26
  • you need to save current volume in some variable and when volume change save that volume in other variable and compare those variable if its different you can do that you want on volume change. – Jaimin Soni May 06 '15 at 06:29
  • 1
    Actually I was searching for an eventListener. But now you saved my time. Thank you Jaimin. – Anna May 06 '15 at 06:35
  • There is no eventListener for volume change in Youtube api. And dont forget to mark this answer as useful if it is. – Jaimin Soni May 06 '15 at 06:37