When creating MediaSource using createMediaSource(mediaItem) and it was populated with subtitles the player will not consider them as text tracks
See original GitHub issueHi,
Given MediaItem.Subtitle list is missing in playback text tracks if the MediaSource is built from given MediaItem having the subtitles
When I was trying to explore the usage MediaSource instead of MediaItem for the Playback URL headers modifications
I have populated the MediaItem playback params with the external subtitles. I could not see that external subtitle in the tracks dialog when I tested this solution
I have modified a bit the demo app main activity to call setMediaSource
instead of setMediaItems
I have also assumed that single non drm dash media without subtitles is selected.
I have populated subtitleList and set it to mediaItem in pos 0.
created a dash media source
and called
player.setMediaSource(dashMediaSource,!haveStartPosition);
instead of
player.setMediaItems(mediaItems, /* resetPosition= */ !haveStartPosition);
then called prepare
List<MediaItem.Subtitle> subtitleList = new ArrayList<>();
String url = "https://storage.googleapis.com/exoplayer-test-media-1/webvtt/numeric-lines.vtt";
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);
...
mediaItems.get(0).buildUpon().setSubtitles(subtitleList);
...
DashMediaSource dashMediaSource = new DashMediaSource.Factory(new DefaultDashChunkSource.Factory(dataSourceFactory), dataSourceFactory).createMediaSource(mediaItems.get(0));
player.setMediaSource(dashMediaSource,!haveStartPosition);
//player.setMediaItems(mediaItems, /* resetPosition= */ !haveStartPosition);
player.prepare();
Version: Exo Player version: 2.12.3 Android 10 Samsung Galaxy 10e
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (4 by maintainers)
Top GitHub Comments
Ah right, yes, you do need a
MediaItem
to give to the non-deprecatedcreateMediaSource
methods, even when building aMediaSource
instances outside of the player. So point (2) of my previous response wasn’t really correct.Point (1) still is correct though: If you need side-loaded subtitle support then you should use
DefaultMediaSourceFactory
rather thanDashMediaSource.Factory
.DefaultMediaSourceFactory
has the additional logic needed to build aMergingMediaSource
for the side-loaded subtitles. Alternatively, you can useDashMediaSource.Factory
to build aDashMediaSource
, and then you can wrap it in aMergingMediaSource
yourself.It is a bit confusing that some of the
MediaSourceFactory
implementations only support a subset of what can be specified in theMediaItem
. In this example, it’s confusing thatDashMediaSource.Factory
does not support side-loaded subtitles. We will have a think about how best to document or resolve this.@ojw28 Got it, The I am wondering what is the benefit that we need to give the mediaItem itself to the createMediaSource and not using url in the deprecated api which build the media source? the API actually forces to use MediaItem even if it is not a must.
What do I miss.