Chromecast add subtitle while playing video

1.1k views Asked by At

I can show subtitle(webvtt) using android app using following code

MediaTrack subtitle = new MediaTrack.Builder(0, MediaTrack.TYPE_TEXT)
                            .setName("English")
                            .setSubtype(MediaTrack.SUBTYPE_SUBTITLES)
                            .setContentId(mediaObject.getSubtitleUrl())
                            .setLanguage(Locale.getDefault())
                            .build();

                    tracks.add(subtitle);

My problem is, this approach works when media is loaded initially to Chromecast, so if I want add subtitle later while media is playing I have to reload media again.

Is there work around this? As I have seen some apps doing the desired behavior.

1

There are 1 answers

2
Ali Naddaf On

You'd need to load your media with subtitles included from the beginning. You can have subtitles turned off and then allow user to select one and turn that on or off at run time but in order to have things working, subtitles need to be included at the load time of media.