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

前端 未结 5 758
日久生厌
日久生厌 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:03

    Solution:

        videojs("example_video_1").ready(function() {
            myvideo = this;
    
            var aTextTrack =  this.textTracks()[0];
            aTextTrack.on('loaded', function() {
                console.log('here it is');
                cues = aTextTrack.cues();   //subtitles content is here
                console.log('Ready State', aTextTrack.readyState()) 
                console.log('Cues', cues);
            });
    
            //this method call triggers the subtitles to be loaded and loaded trigger
            aTextTrack.show();
        });
    

    Result:


    PS. Code found here.

提交回复
热议问题