Open MagicUnderHood opened 3 years ago
I can reproduce what you're seeing on the dev-v2 branch. I modified DefaultDataSource#read()
as below to simulate a slow load, then played the "Subtitles > WebVTT positioning" sample in the Demo app. Video playback is delayed until the subtitles are available:
@Override
public int read(byte[] buffer, int offset, int readLength) throws IOException {
if (getUri().getPath().endsWith(".vtt")) {
try {
Thread.sleep(3_000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
return Assertions.checkNotNull(dataSource).read(buffer, offset, readLength);
}
This is happening because SingleSampleMediaPeriod
reports its buffered position as 0 until loading is complete, then it reports C.TIME_END_OF_SOURCE
:
https://github.com/google/ExoPlayer/blob/7d3f54a375fac04a746ca76a8f2e1ad32c8b45b2/library/core/src/main/java/com/google/android/exoplayer2/source/SingleSampleMediaPeriod.java#L195-L197
I changed this locally to always return C.TIME_END_OF_SOURCE
and it allows video playback to start immediately, with the subtitles appearing as soon as their load completes.
There's currently no toggle on SingleSampleMediaSource
to change this behaviour - I'll keep this issue open to track that as a possible enhancement. In the meantime if you want to change this behaviour yourself you can either directly edit a local copy of ExoPlayer or fork SingleSampleMediaSource and Period into your own project and make the change there.
Thanks for your reply! I will wait for enhancement and try the suggested options.
Description
I am using exoplayer 2.11.4 and am adding multiple .srt subtitles to a video using SingleSampleMediaSource and MergingMediaSource. When the video starts, the player always sends a request for the first subtitles from the list. If delay (timeout) is set on this request (I use Fiddler for this), then the player waits for a response and does not start playing. The player is in BUFFERING state and the user cannot watch the video. I want the subtitle request delay not to interfere with the video playback.
I already ignore 404 subtitle request errors by setting setTreatLoadErrorsAsEndOfStream(true), but that doesn't help in case of a delay. I also do not allow subtitle re-requests via CaptionsLoadErrorPolicy.
My code:
Reproduction steps
A full bug report captured from the device No bug report required as the player does not produce any errors.
Version of ExoPlayer being used ExoPlayer version 2.11.4
Device(s) and version(s) of Android being used Pixel 2 android emulator, Android version 10