1

是否可以检测嵌入式播放器中的 youtube 字幕是打开还是关闭?

如果用户选择显示字幕,目前无法抑制字幕。如果字幕打开,我想显示一条自定义消息。

据我所知,在文档中没有提到这一点。

4

2 回答 2

6

我在他们的 api 文档中没有找到这个,但是使用你的 youtube 播放器对象你应该能够做到:

player.getOptions("captions") || player.getOptions("cc")  //detects if captions were ever loaded at one point.

也可以通过js开启:

player.loadModule("captions");  //Works for html5 ignored by AS3
player.loadModule("cc");  //Works for AS3 ignored by html5

将其关闭:

player.unloadModule("captions");  //Works for html5 ignored by AS3
player.unloadModule("cc");  //Works for AS3 ignored by html5

如果加载了模块,则更改哪种语言:

player.setOption("captions", "track", {"languageCode": "es"});  //Works for html5 ignored by AS3
player.setOption("cc", "track", {"languageCode": "es"});  //Works for AS3 ignored by html5
于 2014-03-29T01:24:06.407 回答
5

像馅饼一样容易,你可以;)

<!DOCTYPE html>
<html>
<head>
<title>test</title>
</head>
<body>
<script src="//ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js"></script>
  <div id="ytapiplayer">
    You need Flash player 8+ and JavaScript enabled to view this video.
  </div>

  <script type="text/javascript">

    var params = { allowScriptAccess: "always" };
    var atts = { id: "myytplayer" };
    swfobject.embedSWF("http://www.youtube.com/v/QRS8MkLhQmM?enablejsapi=1&playerapiid=ytplayer&version=3",
                       "ytapiplayer", "640", "480", "8", null, null, params, atts);

    var stateChange = function(a) {
            if (ytplayer.getOptions().indexOf("cc") !== -1) {
        alert("closed captions are on");
      } else {
        alert("closed captions are off");
      }
    }
   function onYouTubePlayerReady(playerId) {
      ytplayer = document.getElementById("myytplayer");
      ytplayer.addEventListener("onStateChange","stateChange");
    }
  </script></body>
</html>

顺便说一句:谷歌摇滚;)

这应该可以解决问题 - 请不要在生产模式下使用它 - 这只是一个快速总结。你需要倾听你想要的状态,我只是在任何事件中提醒;)

于 2012-08-28T16:10:56.993 回答