iframe プレーヤーを使用して、YouTube ビデオにクローズド キャプションを表示する際に問題が発生しています。
私が使用しているコードは次のとおりです。
<!DOCTYPE html>
<html>
<body>
<!-- 1. The <iframe> (and video player) will replace this <div> tag. -->
<div id="player"></div>
<script>
// 2. This code loads the IFrame Player API code asynchronously.
var tag = document.createElement('script');
tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
// 3. This function creates an <iframe> (and YouTube player)
// after the API code downloads.
var player;
function onYouTubeIframeAPIReady() {
player = new YT.Player('player', {
height: '390',
width: '640',
videoId: 'M7lc1UVf-VE',
events: {
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange
}
});
}
// 4. The API will call this function when the video player is ready.
function onPlayerReady(event) {
event.target.playVideo();
}
// 5. The API calls this function when the player's state changes.
// The function indicates that when playing a video (state=1),
// the player should play for six seconds and then stop.
function onPlayerStateChange(event) {
event.target.loadModule('captions');
}
</script>
</body>
</html>
ここに要点があります https://gist.github.com/khirakawa/0a81b3039a85b9875b59
これは基本的に、API リファレンス ページhttps://developers.google.com/youtube/iframe_api_referenceにあるサンプル コードと同じです。event.target.loadModule('captions');
プレイヤーの状態変更イベントを呼び出します。
キャプション モジュールの読み込みに関する API リファレンス ページのドキュメントは見つかりませんでしたが、このチケットでキャプション モジュールを読み込むコードを見つけましたhttps://code.google.com/p/gdata-issues/issues/detail? id=444
SafariとChromeの両方でこれを試しましたが、うまくいきませんでした。
YouTubeを開いたときに表示されるローカルストレージの値は次のとおりです。
yt-remote-connected-devices {"data":"[]","expiration":1412291704974,"creation":1412205304974}
yt-remote-device-id {"data":"27238aac-9452-4ae8-9b9f-1e29278e4d3b","expiration":1443741293991,"creation":1412205293992}
yt-remote-load-account-screens {"data":"false","expiration":1443741304972,"creation":1412205304972}
yt-remote-online-screens {"data":"[]","expiration":1412205364973,"creation":1412205304973}
キャプションのエントリが欠落していることに注意してください (キー値が何であったかは思い出せませんが、そのうちの 2 つがあったことは知っています。1 つはキャプションを有効にするためのもので、もう 1 つはキャプション設定のためのものです)。
cc_load_policy をオンにすると、デモ ページ ( https://developers.google.com/youtube/youtube_player_demo ) にクローズド キャプションが表示されますが、これは AS3 オプションのみです。
これは10月6日に機能していましたが、もう機能しません。YouTube スクリプト自体が変更されたかどうかはわかりません。
ハンドラーに移動しようとしevent.target.loadModule('captions');
ましたonPlayerReady
が、それもうまくいきませんでした。
どんな助けでも大歓迎です。