javascript - 如何识别 youtube 播放器中的音量变化

标签 javascript angularjs youtube youtube-iframe-api

我正在使用“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/

相关文章:

javascript - ajax 大表单提交的更短方法

angularjs - 用咕噜声构建 Angular 应用程序,应用程序无法加载

ios - iOS中YouTube和LinkedIn URL方案的使用

laravel - Laravel如何在Youtube API上获取访问 token

javascript - Node.js 中的 fs 看不懂~/

c# - colorbox + asp.net 按钮不会回发

angularjs - 如何避免在多 Angular 用户界面选择中出现重复

javascript - AngularJS,UI Bootstrap DropDown Toggle,如果绑定(bind)了参数,则 ng-click 不会触发

python - 如何使用 Python 下载有效的 Youtube 视频 HTML 页面?

javascript - 尝试从 iframe 中获取选择值