youtube-iframe-api closed captioning troubles

最后都变了- 提交于 2019-12-09 13:30:08

问题


Spent a better part of yesterday 6/12/2017 trying figure out why my captioning was not working when I was using the YouTube iframe embed code (generated from the Share > Embed button).

After much experimentation, I narrowed the problem down to what has already been identified. Closed captioning was not working as the captioning was automatically generated. Once I manually created the closed captioning, everything seemed to work fine. I didn't even have to use the cc_load_policy=1 parameter.

BUT... Today 6/13/2017, I happened to be working with the same video files and all of a sudden I got different behavior. When I play the video from a regular YouTube page, I see the captioning. When I play the video from the iframe embedded players I do not. Tried all sorts of goofy things to get things to work based on reading.

  • recreated the english closed caption (manually created a blurb at beginning).
  • set the cc_load_policy=1 parameter
  • set yt:cc=on as a tag
  • some other goofy things that are not worth mentioning.

CAPTIONING

note: In both cases the domain was: http://www.youtube.com I could only include 2 links in post.

/watch?v=EExO_6PVIXk

NO CAPTIONING:

/embed/EExO_6PVIXk /embed/EExO_6PVIXk?cc_load_policy=1

I am at a loss. Any direction would be appreciated.

John


回答1:


Heard through the grapevine that something changed with the YouTube iFrame API yesterday (6/14/17) where CC started to work.

With some testing, I got mixed results (but am working):

1) As of now (6/15/17), the embed video links now show the CC button and will show CC if you had previously enabled closed captioning (kept track in local storage under "yt-html5-player-modules::subtitlesModuleData::module-enabled".

2) If you provide documented the "cc_load_policy=1" parameter to the URL (of the iFrame embed) closed captioning will show regardless of the value in local storage.

3) What didn't work is me loading the iframe as follows:

    <iframe
      id="futusign_youtube"
      style="visibility: hidden;"
      frameborder="0"
      src="https://www.youtube.com/embed/XIMLoLxmTDw?enablejsapi=1"
    ></iframe>

and then trying to set the CC policy in playerVars:

    var player = new window.YT.Player('futusign_youtube', {
      playerVars: {
        'controls': 0,
        'enablejsapi': 1,
        'showinfo': 0,
        'rel': 0,
        'cc_load_policy': 1,
      },
      events: {
        'onReady': onPlayerReady,
        'onStateChange': onPlayerStateChange,
        'onError': onPlayerError,
      }
    });

4) The work-around is to set the cc_load_policy=1 on the URL of the src to the iFrame.

    <iframe
      id="futusign_youtube"
      style="visibility: hidden;"
      frameborder="0"
      src="https://www.youtube.com/embed/XIMLoLxmTDw?enablejsapi=1&cc_load_policy=1"
    ></iframe>



回答2:


I think this might be a duplicate of this problem:

Embed Youtube with Captions on by default not working

...where adding the cc_lang_pref=en option (if you want English) solves the problem.



来源:https://stackoverflow.com/questions/44528683/youtube-iframe-api-closed-captioning-troubles

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