Display subtitles in Chromecast on Android

Hello friends, I’m trying to play content through ChromeCast with external subtitles in WebVTT format, but it’s not being displayed on the screen. No errors are found in the log.

I took the BasicCasting example project and just included the lines in initializePlayer():

ArrayList<SubtitleTrack> subtitles = new ArrayList<SubtitleTrack>();
subtitles.add(new SubtitleTrack("https://downtown.homologacao.attri.com.br/storage/legendas/1614372023010463b5d01de0310.vtt", null, "pt-br", "1", true, "pt-br"));

 sourceItem.setSubtitleTracks(subtitles);

The subtitle works perfectly on the smartphone, it appears in the subtitle list and I can select it. Even when Chromecast starts it appears in the options and I can select it too. But nothing happens on TV.

Does anyone have an idea?
Thanks!

Hi Nicolas,
in order to be able to view side loaded subtitle tracks on Chromecast the URL needs to be provided with the according CORS headers.

You can verify that this is the problem by using one of the free online CORS proxy like https://allorigins.win/:

ArrayList<SubtitleTrack> subtitles = new ArrayList<SubtitleTrack>();
subtitles.add(new SubtitleTrack("https://api.allorigins.win/raw?url=https://downtown.homologacao.attri.com.br/storage/legendas/1614372023010463b5d01de0310.vtt", null, "pt-br", "1", true, "pt-br"));

 sourceItem.setSubtitleTracks(subtitles);

E.g. the following headers should do the trick:

Referrer Policy: strict-origin-when-cross-origin
access-control-allow-credentials: true
access-control-allow-headers: Origin, X-Requested-With, Content-Type, Content-Encoding, Accept
access-control-allow-methods: OPTIONS, GET, POST, PATCH, PUT, DELETE
access-control-allow-origin: *

For more details on how to debug such an issue on the cast receiver see this article and this community discussion.

Also see the official documentation on CORS requirements for media tracks used on Chromecast.

This topic was automatically closed 60 minutes after the last reply. New replies are no longer allowed.