HTML5 <audio> textTrack.kind=subtitles cueChange event not working in FireFox

后端 未结 4 2541
北荒
北荒 2021-02-20 01:56

UPDATE:

This issue no longer existing FireFox, cuechange now works. Embedded base64 images also render.

The original code is a simple implementation of am

4条回答
  •  天涯浪人
    2021-02-20 02:19

    Still not fixed as of v39, August 2015. Here's the ugly workaround I've been putting together to check for changes to the activeCues list. It's working as a proof of concept, now I need to rewrite my code for browsers that do properly support onCueChange so the fallback happens properly.

    var v = document.getElementsByTagName('video')[0];
    var t = v.textTracks;
    var la = [];
    for(l = 0; l < t.length; l++){
        la[l] = '';
    };
    
    var onchangeTest =  (function isEventSupported(eventName) {
        var isSupported = ('oncuechange' in t[0]);
        if (isSupported) {
            return true;
        } else {
            return false;
        };
    })();
    
    v.ontimeupdate = function(){
        if(!onchangeTest){
            var activeCues ="";
            var delim ="";
            for(i = 0; i < t.length; i++){
                if(t[i].kind == 'captions' || t[i].kind == 'subtitles'){
                    delim = "
    "; } else { delim = "\n"; }; a = v[i].activeCues; if(a){ var tt = ''; for(ii = 0; ii < a.length; ii++){ tt += a[ii].text + delim; if(tt !== la[i]){ la[i] = tt; console.log('tt: ' + tt + ' la[' + i + ']: ' + la[i]); }; }; }; }; }; };

提交回复
热议问题