Skip to content

Ignore load errors in subtitle tracks sideloaded using SingleSampleMediaSource #3140

@minaEweida

Description

@minaEweida

I am using MergingMediaSource in order to display Video and subtitles. For some reason the text source file might be removed from the server so the url will return 404, giving the following exception com.google.android.exoplayer2.upstream.HttpDataSource$InvalidResponseCodeException: Response code: 404

At this point it makes sense, the problem is I can't play the video if this happens although I expect that if the text source is not found, I could at least play the video.

Below you can find the code snippet for preparing the media links

MediaSource videoSource = new ExtractorMediaSource(mp4VideoUri, dataSourceFactory, extractorsFactory, null, null);

Format textFormat;
MediaSource[] mediaSources = new MediaSource[videoDetailsModel.getVideoSubtitleModels().size() + 1];
mediaSources[0] = videoSource;
for (int i = 0; i < videoSubtitleModels.size(); i++) {
  VideoSubtitleModel videoSubtitleModel = videoSubtitleModels.get(i);
  textFormat = Format.createTextSampleFormat(null, videoSubtitleModel.getCaptionMimeType(), null, Format.NO_VALUE, Format.NO_VALUE, videoSubtitleModel.getCaptionSrcLang(), null);
  mediaSources[i + 1] = new 
  SingleSampleMediaSource(Uri.parse(videoSubtitleModel.getCaptioningUrl()), dataSourceFactory, textFormat, C.TIME_UNSET);
}
MediaSource mediaSourceWithText = new MergingMediaSource(mediaSources);

// Prepare the player with the source.
player.prepare(mediaSourceWithText);

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions