Is there any way to get current caption's text from video tag using Video.js?

前端 未结 5 729
日久生厌
日久生厌 2021-01-06 18:30

I want to get current subtitles\' text during playing a video (and than implement own subtitles block (i.e. to hide original) and also use the information in a few different

5条回答
  •  时光说笑
    2021-01-06 19:08

    This code gets the current cue and put into the element

    (function(){
    
        var video = document.querySelector('video');
        var span = document.querySelector('span');
    
        if (!video.textTracks) return;
    
        var track = video.textTracks[0];
        track.mode = 'hidden';
    
        track.oncuechange = function(e) {
    
            var cue = this.activeCues[0];
            if (cue) {
                span.innerHTML = '';
                span.appendChild(cue.getCueAsHTML());
            }
    
        };
    })()
    

    Here is the tutorial :Getting Started With the Track Element

提交回复
热议问题