miloproductionsinc/cordova-plugin-chromecast

Discussion - How to load subtitles

Closed this issue · 4 comments

Hi,

Do you know how to load subtitles?

I've tried this:

        var englishSubtitle = new chrome.cast.media.Track(1, chrome.cast.media.TrackType.TEXT);

        englishSubtitle.trackContentId = 'https://thepaciellogroup.github.io/AT-browser-tests/video/subtitles-en.vtt';
        englishSubtitle.trackContentType = 'text/vtt';
        englishSubtitle.subtype = chrome.cast.media.TextTrackType.SUBTITLES;
        englishSubtitle.name = 'English Subtitles';
        englishSubtitle.language = 'en-US';
        englishSubtitle.customData = null;


        var videoUrl = 'https://ia801302.us.archive.org/1/items/TheWater_201510/TheWater.mp4';
        var mediaInfo = new chrome.cast.media.MediaInfo(videoUrl, 'video/mp4');



        mediaInfo.metadata = {
          title: 'My Title',
          images: [new chrome.cast.Image('https://image.tmdb.org/t/p/w300_and_h450_bestv2/udDclJoHjfjb8Ekgsd4FDteOkCU.jpg')],
          tracks:  [englishSubtitle]
        };
        

But it kills the app (removing the tracks doesn't kill the app).

I've also tried the mentioned method here with no luck: https://gist.github.com/guerrerocarlos/3aca64069853d8d24a83b481246f23ca

Thanks

I haven’t ever tried subtitles. My company doesn’t require this, so I won’t be able to help fix this. (I have no time sorry :( )

But my guess is that this will not be too difficult to add. (Since it appears to either be something that is passed through metadata or mediaInfo.)

I would figure out which is the correct method be testing on chrome desktop first.

Since it is crashing the app, most likely it will require a bit of work on the native side of the plugin.

Probably, it will be just explicitly handling the subtitle/tracks so that they are sent, received and passed to native functions correctly.

I think the code you linked is probably closer to/doing it right.

According to the official docs the tracks are a direct attribute of the MediaInfo object:
https://developers.google.com/cast/docs/reference/chrome/chrome.cast.media.MediaInfo.html#tracks

Just quickly checked 'loadMedia' in 'chrome.cast.js', looks like we aren't even sending the tracks attribute.

Really, we should just sending the entire mediaInfo object, not individual attributes, but I didn't have time to refactor this.

Ok, thanks, I'll see if I can do something, I was just playing with this.