google / ExoPlayer

This project is deprecated and stale. The latest ExoPlayer code is available in https://github.com/androidx/media
https://developer.android.com/media/media3/exoplayer
Apache License 2.0
21.7k stars 6.02k forks source link

MergingMediaSource with ConcatenatingMediaSource throws IllegalMergeException #4435

Closed AniLabXTeam closed 6 years ago

AniLabXTeam commented 6 years ago

Issue description

I'm using ConcatenatingMediaSource for two video parts concatenation. This parts is on server. Sometimes, this "parts" has VTT subtitles. And if i try to merge conctatenated sources with SingleSampleMediaSource an prepare player i'l get IllegalMergeException.

How can i merge this sources?

Reproduction steps

Here is my code that i use for merging sources

// concatenating parts
MediaSource mediaSource1 = new ExtractorMediaSource.Factory(mediaDataSourceFactory).createMediaSource(Uri.parse(videoUriPartsList.get(1)));
MediaSource mediaSource2 = new ExtractorMediaSource.Factory(mediaDataSourceFactory).createMediaSource(Uri.parse(videoUriPartsList.get(2)));

ConcatenatingMediaSource concatenatedMediaSource = new ConcatenatingMediaSource(mediaSource1 , mediaSource2);

// creating source for subtitles
MediaSource subtitleSource = new SingleSampleMediaSource.Factory(mediaDataSourceFactory).createMediaSource(uri, textFormat, C.TIME_UNSET);

// merging sources
MergingMediaSource mergedSource = new MergingMediaSource(concatenatedMediaSource, subtitleSource);

After prepare i got IllegalMergeException in log and called onPlayerError in Player.EventListener()

Link to test content

part1 = http://lh3.googleusercontent.com/1LRpp1BPxe_5iFXmVcdtwgNlG3nOBhGtqWEiLEi5yGBH1j0gui6CtGLzyGoMdbwrZRNou3-Apu4=m37?ratebypass=yes part2 = http://lh3.googleusercontent.com/vLPk-fZMVObQahl7aYVIcBKB8MaAUWEIJlJ2pjjxgK7k92GXl47xolOHMeA9MfBnxu_-EH5DBpc=m37?ratebypass=yes

subtitlesLink = https://smotret-anime.ru/translations/vtt/542583

Version of ExoPlayer being used

ExoPlayer 2.8.1

Device(s) and version(s) of Android being used

Xiaomi Redmi 4X, Android 8.1 Some users reports that have same issue, but i don't know what phone/Android version they use

andrewlewis commented 6 years ago

The exception is thrown due to merging a source that has two periods (the two videos being concatenated) with a source that has one period (the single sample containing subtitles).

This looks like a duplicate of #3812. One way to proceed would be to split up the subtitles into two parts, one corresponding to each video in the concatenation.

AniLabXTeam commented 6 years ago

@andrewlewis so, there is no any way to merge this files together without sibtitles splitting? Even if duration of each part is known before concatenation (and using ClippingMediaSource) - merge will not work, because concatenating always create more than one peroid?

andrewlewis commented 6 years ago

Concatenation does always create more than one period. I think splitting the subtitles file is going to be the easiest way to fix this.

AniLabXTeam commented 6 years ago

@andrewlewis thank you for responce. It can lead to errors if some string from subtitles may show in end of first part and on start of second part? Or i need split this string too for exact timings?

Example. First parts duration 14:00. Subtitles has string that showing from 13:58 to 14:05. But this last five seconds in another period. So i need split it too?

andrewlewis commented 6 years ago

Yes. That cue would need to be duplicated at the start of the second section, then the time ranges of the cues would need to be updated.