我正在嘗試使用以下代碼行按鈕單擊動態更改字幕軌道,但它不會更改字幕。爲什麼?動態更改字幕視頻 - HTML5
$('#turnoff').click(function(){
$('.player-content-video track').attr('default',false);
});
$('#english').click(function(){
$('.player-content-video track').attr('default',false);
$('.player-content-video track').eq(0).attr('default',false);
});
$('#chinese').click(function(){
$('.player-content-video track').eq(1).attr('default',false);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<video class="player-content-video">
<track src="sample_video-en.vtt" srclang="en" kind="subtitles" default="true">
<track src="sample_video-ch.vtt" default="false" srclang="ch" kind="subtitles">
<source src="http://www.w3schools.com/html/mov_bbb.mp4" type="video/mp4">
</video>
<br/>
<button id="turnoff" >NO SUBTITLE</button>
<button id="english" >ENGLISH</button>
<button id="chinese" >CHINESE</button>
注:在這個例子中track
src
僅供代碼演示。
檢查這個問題https://developer.mozilla.org/en-US/Apps/Fundamentals/Audio_and_video_delivery/Adding_captions_and_subtitles_to_HTML5_video#Subtitle_implementation你需要改變MDN文章'video.textTracks'數組屬性中項目的'mode' – casraf
請注意,stacksnippets中'track'元素的源不是完整路徑 – guest271314
trach src僅用於演示 – Shin