Unable to catch ExoPlaybackException: Source error
Asked Answered
U

2

10

No matter what I try, I am not able to catch "ExoPlaybackException: Source error" error. The video playback stops and I can see Exoplayer error thrown. The Stacktrace is below:

2021-02-09 22:36:51.917 27876-19080/com.... E/ExoPlayerImplInternal: Playback error
      com.google.android.exoplayer2.ExoPlaybackException: Source error
        at com.google.android.exoplayer2.ExoPlayerImplInternal.handleMessage(ExoPlayerImplInternal.java:554)
        at android.os.Handler.dispatchMessage(Handler.java:103)
        at android.os.Looper.loop(Looper.java:237)
        at android.os.HandlerThread.run(HandlerThread.java:67)
     Caused by: com.google.android.exoplayer2.source.BehindLiveWindowException
        at com.google.android.exoplayer2.source.hls.HlsChunkSource.getNextChunk(HlsChunkSource.java:308)
        at com.google.android.exoplayer2.source.hls.HlsSampleStreamWrapper.continueLoading(HlsSampleStreamWrapper.java:662)
        at com.google.android.exoplayer2.source.CompositeSequenceableLoader.continueLoading(CompositeSequenceableLoader.java:80)
        at com.google.android.exoplayer2.source.hls.HlsMediaPeriod.continueLoading(HlsMediaPeriod.java:365)
        at com.google.android.exoplayer2.source.MaskingMediaPeriod.continueLoading(MaskingMediaPeriod.java:219)
        at com.google.android.exoplayer2.MediaPeriodHolder.continueLoading(MediaPeriodHolder.java:218)
        at com.google.android.exoplayer2.ExoPlayerImplInternal.maybeContinueLoading(ExoPlayerImplInternal.java:2011)
        at com.google.android.exoplayer2.ExoPlayerImplInternal.handleContinueLoadingRequested(ExoPlayerImplInternal.java:1992)
        at com.google.android.exoplayer2.ExoPlayerImplInternal.handleMessage(ExoPlayerImplInternal.java:489)
        at android.os.Handler.dispatchMessage(Handler.java:103) 
        at android.os.Looper.loop(Looper.java:237) 
        at android.os.HandlerThread.run(HandlerThread.java:67) 

This is my "onPlayerError" method, but it does not seem to be called for some reason.

private class PlayerEventListener implements Player.EventListener {
...
@Override
        public void onPlayerError(ExoPlaybackException error) {
            switch (error.type) {
                case ExoPlaybackException.TYPE_SOURCE:
                    Log.e(TAG, "TYPE_SOURCE: " + error.getSourceException().getMessage());
                    break;

                case ExoPlaybackException.TYPE_RENDERER:
                    Log.e(TAG, "TYPE_RENDERER: " + error.getRendererException().getMessage());
                    break;

                case ExoPlaybackException.TYPE_UNEXPECTED:
                    Log.e(TAG, "TYPE_UNEXPECTED: " + error.getUnexpectedException().getMessage());
                    break;
            }
        }
...
}

player.addListener(new PlayerEventListener());

Am I missing anything?

Unfathomable answered 10/2, 2021 at 6:45 Comment(2)
It's says source error, did you try playing working [link ](ottverse.com/free-hls-m3u8-test-urls)Serranid
Thanks, that's useful! I tried these streams and they all work fine. When I throttle the bandwidth it will just "buffer" more often, but never fail. There is just this one particular HLS stream, that throws the "Source Error" exceptions. Usually when the bandwidth is low.Unfathomable
U
4

Not sure where I was looking... but the error seems to be caught in the "onPlayerError()" method.

It is caught right here:

switch (error.type) {
                case ExoPlaybackException.TYPE_SOURCE:
                    Log.e(TAG, "TYPE_SOURCE: " + error.getSourceException().getMessage());
                    //Restart the playback
                    play(mediaItem);
                    break;

Currently, I am handling the error in a way that I restart the playback.

Unfathomable answered 12/2, 2021 at 6:35 Comment(2)
doesn't this put it into an infinite loop if the playback error is a legitimate one (IE the video URL is invalid or is throwing a 403)?Botnick
Can confirm that yes, this does throw it into an infinite loop if the error is genuine.Botnick
C
1

Additional Information.

In customer product, when sharing the screen on the web, only the video track was recorded, without audio, into HLS format. Because of this, on iOS with AVPlayer, and on Android with ExoPlayer v2.18, and on Flutter with VideoPlayer v2.4.8, there was an error:

com.google.android.exoplayer2.ExoPlaybackException: Source error

The problem was fixed by adding a silent audio track when recording.

key moment: hls must contain 2 tracks at the same time: audio and video

Concavity answered 23/8, 2022 at 18:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.