Monday, 17 May 2021

Using CastPlayer with Subtitles on Android

I'm attempting to use the MediaItem class to load videos and show subtitles on the exoplayer2 CastPlayer. I'm able to see subtitles on the phone before casting and the video plays fine when cast to a TV using application/dash+xml format. However, I'm not able to figure out how to get subtitles to appear on the TV. I have added the MediaItem.Subtitle using MediaItem.Builder().setSubtitles(subtitleList). Previously I was able to do so with the deprecated MediaInfo class. I can't see any methods in the CastPlayer class to turn them on or how to customize the PlayerControlView to add a subtitle/caption button. Any ideas are greatly appreciated.

List<MediaItem.Subtitle> subtitleList = new ArrayList<>();
      MediaItem.Subtitle externalSubtitle = new MediaItem.Subtitle(Uri.parse(url), MimeTypes.TEXT_VTT,"en", C.SELECTION_FLAG_DEFAULT, C.ROLE_FLAG_SUBTITLE, "ENGLISH-EXTERNAL");
    subtitleList.add(externalSubtitle);
   
MediaItem mediaItem =   new MediaItem.Builder()
                .setUri(url)
                .setMediaMetadata(mediaMetadata)
                .setMimeType(mimeType)
                .setSubtitles(subtitleList)
                .build();

castPlayer.setMediaItem(mMediaItem);


from Using CastPlayer with Subtitles on Android

No comments:

Post a Comment