Exoplayer: Selecting one subtitle among merged resources

Created on 17 Feb 2019  Β·  10Comments  Β·  Source: google/ExoPlayer

(Question)
I'm getting into this library slowly, but thoroughly due to achieve what I want..

So far so good, just the fact that there is no callback method for failing to getting subtitle file..? (Please let me know if there is)

Anyway, I have "a video" and "subtitles in 3 different languages", I could find that I can merge them into one mediaSource.

And now, I want, people to choose which language subtitle they want right?

And I couldn't find a method for this.. I was kind of understanding "TrackSelector" but it just feels like it's not a method for subtitle..?

How can I set one subtitle to play..?

Thank you.

question

All 10 comments

If I want to make people to choose subtitles...kinda feels like I should be able to merge subtitle sources with at least one string like (Korean, English, etc...)

FYI, choosing subtitles Dialog in Netflix is what I want to achieve...

If you sideload your text tracks with a MergingMediaSource as described in the developer guide, you can select text tracks by using the DefaultTrackSelector. The developer guide has a section around track selection which covers the DefaultTrackSelector.

You can use DefaultTrackSelector.Parameters to set the preferred language:

trackSelector.setParameters(
  trackSelector
      .buildUponParameters()
      .setPreferredTextLanguage("deu")
      .build());

The UI module of the library already has a TrackSelectionView which builds a view from the track information in a generic way.

Okay.. I've dug deeper and figured out.. the core of this function so far is debugging the whole project...

Though, I think the guide could be more generous...

Anyway, the parameter I should have looked at for changing subtitles after merging them was,
rendererIndex in val dialogPair = TrackSelectionView.getDialog(this, title, trackSelector, rendererIndex)

rendererIndex Choices are-
_0 == Video
1 == Audio
2 == Subtitle_

Thank you, now I understand this library more... :) πŸ‘
Now the issue is customizing the dialog..

  1. In callback method onTracksChanged, I can get changed parameter trackSelection, and the length of it is weird..(for me, it's always 5) and it's pretty tricky to get which language of subtitle I chose...
    For usage, I'd like to save the language that user selected and set that data as a default later.

  2. How can I customize the view of the dialog?
    For example in Netflix, they provide one dialog to change bandwidth & subtitle.

I'd use the DefaultTrackSelector to build your dialog. You can use C.TRACK_TYPE_TEXT to get the text tracks, so you don't need integer literals. Then iterate through the trackGroups of the text track to get the format of each available track and build up the UI for each entry. You can iterate as follows:

MappedTrackInfo mappedTrackInfo = defaultTrackSelector.getCurrentMappedTrackInfo();
int trackType = mappedTrackInfo.getRendererType(rendererIndex);
if (trackType == C.TRACK_TYPE_TEXT) {
  TrackGroupArray trackGroups = mappedTrackInfo.getTrackGroups(rendererIndex);
  for (int i = 0; i < trackGroups.length; i++) {
    for (int j = 0; j < trackGroups.get(i).length; j++) {
      Format format = trackGroups.get(i).getFormat(j);
      Log.d("TAG", "language: " + format.language);
    }
  }
}

To select a given language when the user has chosen it, I'd use defaultTrackSelector.setPreferredTextLanguage(format.language) to select the subtitle language.

Thanks for the updats, but this is what I was talking about here

C.TRACK_TYPE_TEXT is 3.
And rendererIndex should be 2 to get those data in getTrackGroups

Yes, you are right, there is another indirection to check the track type. I corrected the snippet above

Speaking of this issue..
Most of people are just using integer value for rendererIndex..
What do you think of adding Integer constant values?
Just like C.RENDERER_TYPE_VIDEO = 0, C.RENDERER_TYPE_AUDIO = 1, C.RENDERER_TYPE_TEXT = 2

I think it makes sense how it is and to not make the assumption that a given renderer index is always of the same type. This would come for the price of being less flexible, while not paying really much.

I close this issue for know. Please reopen if you think I need to add something. Many thanks!

Many thanks to you!
I learned a lot, but also leaving some guidance about these on "Developer
Guide page" would be really helpful for the future fellows and save your
time..? :)

Take care!

2019λ…„ 2μ›” 22일 (금) μ˜€μ „ 6:53, Marc Baechinger notifications@github.comλ‹˜μ΄ μž‘μ„±:

I think it makes sense how it is and to not make the assumption that a
given renderer index is always of the same type. This would come for the
price of being less flexible, while not paying really much.

I close this issue for know. Please reopen if you think I need to add
something. Many thanks!

β€”
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/google/ExoPlayer/issues/5522#issuecomment-466181964,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AJ7c673oOTJ7eHtBGc-bL9-qDJ2ewlV_ks5vPxVtgaJpZM4a_Y_W
.

Was this page helpful?
0 / 5 - 0 ratings