I have found a few examples that work with Leanback
and ExoPlayer
and I have all that working but I can't get subtitles/captions to work. The newest Google example I could find (https://github.com/android/tv-samples) has a captions button on the Java sample but they never show up. The Kotlin example has a comment that says // TODO(owahltinez): handle captions
.
I've tried these changes to one of the samples but it didn't help:
private void prepareMediaForPlaying(Uri mediaSourceUri) {
String userAgent = Util.getUserAgent(getActivity(), "VideoPlayerGlue");
DefaultDataSourceFactory defaultDataSourceFactory = new DefaultDataSourceFactory(getActivity(), userAgent);
MediaSource mediaSource =
new ExtractorMediaSource(
mediaSourceUri,
defaultDataSourceFactory,
new DefaultExtractorsFactory(),
null,
null);
String subtitle = "https://subtitledomain/sintel-en.vtt";
Uri uriSubtitle = Uri.parse(subtitle);
MediaSource subtitleMediaSource = new SingleSampleMediaSource.Factory(defaultDataSourceFactory)
.createMediaSource(uriSubtitle, Format.createTextSampleFormat(null, MimeTypes.TEXT_VTT, C.SELECTION_FLAG_FORCED, "n/a"), C.TIME_UNSET);
mediaSource = new MergingMediaSource(mediaSource, subtitleMediaSource);
mPlayer.prepare(mediaSource);
}
And also this change:
mTrackSelector = new DefaultTrackSelector(videoTrackSelectionFactory);
DefaultTrackSelector.Parameters parameters = mTrackSelector.getParameters();
mTrackSelector.setParameters(parameters.withSelectUndeterminedTextLanguage(true));
I've tried changing the language on the subtitle to EN
and that didn't help.
I feel like I'm probably just missing something small but I just don't know what it could be.
Thanks.
Edit: I made a branch and removed all Leanback
code and just left ExoPlayer
stuff untouched and used com.google.android.exoplayer2.ui.PlayerView
in my Fragment
instead of VideoFragment
and subtitles worked without making any other change. So it is like I just need to enable them on the Leanback
side somehow.