youtube embed - force subtitles in specific language with default

前端 未结 4 1908
执笔经年
执笔经年 2020-12-09 05:38

i\'m embedding youtube videos with subtitles in specific language (Hebrew, in my case). im using:

hl=He&cc_load_policy=1

to show the

4条回答
  •  抹茶落季
    2020-12-09 06:06

    I have not found this anywhere in their api docs, but with your youtube player object you should be able to do the following to change it to english captions:

    player.setOption("captions", "track", {"languageCode": "en"});  //Works for html5 ignored by AS3
    player.setOption("cc", "track", {"languageCode": "en"});  //Works for AS3 ignored by html5
    

    You can also do:

    var module;
    if (testplayer.getOptions().indexOf("cc") !== -1) {
        module = "cc";
    } else if (testplayer.getOptions().indexOf("captions") != -1) {{
        module = "captions";
    }
    var tracklist = testplayer.getOption(module, "tracklist");
    
    // then iterate through the tracklist to see if "he" or "en" is there.
    

    You have cc_load_policy=1 but you can also turn it on via js by:

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

    to turn it off:

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

提交回复
热议问题