Chromecast subtitles not working

587 views Asked by At

I'm searching since hours a way to make this work. I need to display the subtitles in a file (VTT) on chromecast.

I have a VideoJS player with subtitles and chromecast plugin.

Here is my code:

       key: 'onSessionSuccess',
    value: function onSessionSuccess(session) {
        var image = undefined;
        var key = undefined;
        var loadRequest = undefined;
        var mediaInfo = undefined;
        var ref = undefined;
        var value = undefined;

        this.apiSession = session;
        var source = this.player_.cache_.src;
        var type = this.player_.currentType();

        _videoJs2['default'].log('Session initialized: ' + session.sessionId + ' source : ' + source + ' type : ' + type);

        mediaInfo = new chrome.cast.media.MediaInfo(source, type);
        mediaInfo.metadata = new chrome.cast.media.GenericMediaMetadata();
        if (this.options_.playerOptions.chromecast.metadata) {
            ref = this.options_.playerOptions.chromecast.metadata;
            for (key in ref) {
                value = ref[key];
                mediaInfo.metadata[key] = value;
            }
        }
        //Add poster image on player
        var poster = this.player().poster();
        if (poster) {
            image = new chrome.cast.Image(poster);
            mediaInfo.metadata.images = [image];
        }

        // Load/Add caption tracks
        var plTracks = this.player().textTracks();
        var remotePlTracks = this.player().remoteTextTrackEls();
        var tracks = [];
        var i = 0;
        var remotePlTrack = undefined;
        var plTrack = undefined;
        var trackId = 0;
        var track = undefined;
        if (plTracks) {
            for (i = 0; i < plTracks.length; i++) {
                plTrack = plTracks.tracks_[i];
                remotePlTrack = remotePlTracks && remotePlTracks.trackElements_ && remotePlTracks.trackElements_[i];
                trackId++;
                track = new chrome.cast.media.Track(trackId, chrome.cast.media.TrackType.TEXT);
                track.trackContentId = remotePlTrack ? remotePlTrack.src : '8306c6ae17b9f81708bcdd8e763e3752_2.vtt';
                track.subtype = chrome.cast.media.TextTrackType.CAPTIONS;
                track.name = plTrack.label;
                track.language = plTrack.language;
                track.customData = null;
                tracks.push(track);
            }
            mediaInfo.textTrackStyle = new chrome.cast.media.TextTrackStyle();
            mediaInfo.textTrackStyle.foregroundColor = '#FFFFFF';
            mediaInfo.textTrackStyle.backgroundColor = '#00000060';
            mediaInfo.textTrackStyle.edgeType = chrome.cast.media.TextTrackEdgeType.DROP_SHADOW;
            mediaInfo.textTrackStyle.windowType = chrome.cast.media.TextTrackWindowType.ROUNDED_CORNERS;

            mediaInfo.metadata.title = "O'Ciné - Propulsé par la liberté";
            mediaInfo.metadata.subtitle = Nom_du_film;
        }
        // Load/Add audio tracks

        try {
            plTracks = this.player().audioTracks();
            if (plTracks) {
                for (i = 0; i < plTracks.length; i++) {
                    plTrack = plTracks.tracks_[i];
                    trackId++;
                    track = new chrome.cast.media.Track(trackId, chrome.cast.media.TrackType.AUDIO);
                    track.subtype = null;
                    track.name = plTrack.label;
                    track.language = plTrack.language;
                    track.customData = null;
                    tracks.push(track);
                }
            }
        } catch (e) {
            _videoJs2['default'].log('get player audioTracks fail' + e);
        }

        if (tracks.length) {
            mediaInfo.tracks = tracks;
        }

        // Request load media source
        loadRequest = new chrome.cast.media.LoadRequest(mediaInfo);

        loadRequest.autoplay = true;
        loadRequest.currentTime = this.player_.currentTime();

        this.apiSession.loadMedia(loadRequest, this.onMediaDiscovered.bind(this), this.castError.bind(this));
        this.apiSession.addUpdateListener(this.onSessionUpdate.bind(this));

The video and the subtitles work well without chromecast but when i launch Chromecast, there is no subtitles on the video.

Can anyone help me?

Thanks

0

There are 0 answers