【问题标题】:YouTube API volume toggleYouTube API 音量切换
【发布时间】:2012-04-10 13:46:18
【问题描述】:

想知道是否可以(以及如何)使用 YouTube iframe API 在播放器外部设置一个 html 按钮或链接来打开和关闭声音。

谢谢,
毛罗

【问题讨论】:

标签: api youtube


【解决方案1】:

请参阅jQuery Youtube Plugin 了解完整规格和下载。
可以像这样声明一个播放器:

 jQuery("#youtube-player-container").tubeplayer({
        width: 600, // the width of the player
        height: 450, // the height of the player
        allowFullScreen: "true", // true by default, allow user to go full screen
        initialVideo: "DkoeNLuMbcI", // the video that is loaded into the player
        preferredQuality: "default",// preferred quality: default, small, medium, large, hd720
        onPlay: function(id){}, // after the play method is called
        onPause: function(){}, // after the pause method is called
        onStop: function(){}, // after the player is stopped
        onSeek: function(time){}, // after the video has been seeked to a defined point
        onMute: function(){}, // after the player is muted
        onUnMute: function(){} // after the player is unmuted
    });
Then just add a link with the desired function:
<a href="#" onClick='jQuery("#youtube-player-container").tubeplayer("mute")'>   
Mute player 

【讨论】:

  • 无需使用任何外部插件,因为 youtube api 已经为您提供了 player.mute()player.unMute() 来切换声音和 player.isMuted() 来检查声道状态。这个解决方案是过度编码,当你可以使用一个简单的 javascript 点击事件时......
猜你喜欢
  • 1970-01-01
  • 2021-04-10
  • 2013-12-30
  • 1970-01-01
  • 2017-10-12
  • 2016-05-12
  • 2016-12-13
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多