How to identify volume change in youtube player

给你一囗甜甜゛ 提交于 2019-12-23 20:33:00

问题


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.


回答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.

For more Detail check this: YouTube Player Controls




回答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 })
  }


来源:https://stackoverflow.com/questions/30068869/how-to-identify-volume-change-in-youtube-player

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!