Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Correct isBehindLiveWindow Error Handling #4143

Merged
merged 2 commits into from
Sep 4, 2024

Conversation

whdudtod1273
Copy link
Contributor

Summary

@Override
    public void onPlayerError(@NonNull PlaybackException e) {
        String errorString = "ExoPlaybackException: " + PlaybackException.getErrorCodeName(e.errorCode);
        String errorCode = "2" + e.errorCode;
        switch(e.errorCode) {
            case PlaybackException.ERROR_CODE_DRM_DEVICE_REVOKED:
            case PlaybackException.ERROR_CODE_DRM_LICENSE_ACQUISITION_FAILED:
            case PlaybackException.ERROR_CODE_DRM_PROVISIONING_FAILED:
            case PlaybackException.ERROR_CODE_DRM_SYSTEM_ERROR:
            case PlaybackException.ERROR_CODE_DRM_UNSPECIFIED:
                if (!hasDrmFailed) {
                    // When DRM fails to reach the app level certificate server it will fail with a source error so we assume that it is DRM related and try one more time
                    hasDrmFailed = true;
                    playerNeedsSource = true;
                    updateResumePosition();
                    initializePlayer();
                    setPlayWhenReady(true);
                    return;
                }
                break;
            default:
                break;
        }
        eventEmitter.onVideoError.invoke(errorString, e, errorCode);
        playerNeedsSource = true;
        if (isBehindLiveWindow(e)) {
            clearResumePosition();
            initializePlayer();
        } else {
            updateResumePosition();
        }
    }

Currently, when the isBehindLiveWindow error (ERROR_CODE_BEHIND_LIVE_WINDOW) occurs in onPlayerError, initializePlayer is executed. However, when initializePlayer is executed, the player is reinitialized, causing it to reload, which results in flickering and feels unnatural.

I believe this error may occur frequently in 3G environments or when the network is poor. In such cases, it would be better to resume playback from the latest live position rather than reinitializing the player.

Motivation

Changes

Then, instead of initializePlayer(), I will execute player?.prepare() and player?.seekToDefaultPosition() to resume the live stream.

Test plan

This is an issue that occurs when playing HLS live streaming in low network mode on Android.

@freeboub
Copy link
Collaborator

freeboub commented Sep 4, 2024

I agree with this change, I will merge it.
BTW the behavior may still change in the future.
To give you more background, There are 2 ways to generate this error with live contents:

  • The use case you describe, having a very short manifest (only few chunks inside) and connectivity issues can cause the problem -> Your fix is well addressing the issue! thank you.
  • Another can happen when you have a pausable live stream. maybe you live is 15min long. in that case it is also reproduced after 15min of pause. This use case is a bit different and I am not 100% sure you put the best behavior here.
    Anyway my point is just to keep in mind. Thank you

@freeboub freeboub merged commit 22c21ad into TheWidlarzGroup:master Sep 4, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants