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

Exoplayer v2.18.1 and some updates - fixes #114

Merged
merged 3 commits into from
Jan 22, 2023

Conversation

PhantomPainX
Copy link
Contributor

@PhantomPainX PhantomPainX commented Jan 15, 2023

Updated dependencies

  • build.gradle (app)
dependencies {
    ...
    implementation 'com.google.android.gms:play-services-cast-framework:21.2.0'
}
  • build.gradle (capacitor-video-player app)
dependencies {
    ...
    implementation 'com.google.android.exoplayer:exoplayer-core:2.18.1'
    implementation 'com.google.android.exoplayer:exoplayer-ui:2.18.1'
    implementation 'com.google.android.exoplayer:exoplayer-hls:2.18.1'
    implementation 'com.google.android.exoplayer:exoplayer-dash:2.18.1'
    implementation 'com.google.android.exoplayer:exoplayer-smoothstreaming:2.18.1'
    implementation 'com.google.android.exoplayer:extension-mediasession:2.18.1'
    implementation 'com.google.android.exoplayer:exoplayer:2.18.1'
    implementation 'com.google.android.exoplayer:extension-cast:2.18.1'
    ...
}

Design and UI fixes

Previously the player used a totally custom UI design. When I updated to exoplayer v2.18.1 I decided to use the default one with some additions: chromecast, pip and resize buttons, titles and back button.

The default design comes with some automatic options like subtitle button, speed and audio selection:

  • PlayerView was changed to StyledPlayerView because of that
  • Buttons has now proper DP size.
  • Fade effect when UI hides/show.

IMG_20230104_155413

Chromecast mode

Previously when using this mode, the player would only show the controls (not stay on screen) with a black background and a message alerting about the cast. This was improved adding an optional param to the initialization called "artwork", this image will be shown in the player, media notification panel and lock screen when casting.

- The artwork must be a remote URL

Chromecast issues

The MediaRouteButton (cast button)

It will hide when you enter in PIP or BK mode. The button won't show up unless you restart the app. This only happens in Android 13 (some users of my app reported me this issue and I confirmed it with an OnePlus 8T)

As this cast thing can only be tested with real devices, I was only able to test it in my other phone (Samsung Galaxy S9+) with Android 10 and this error didn't happen, so I don't know if this happens in Android 11 and 12.

The error is related with addCastStateListener. It fires state 1 (NO_DEVICES_AVAILABLE) when entering in PIP mode or BKMode and never updates the state again.

Subtitles are not available yet
I tried so hard to get the subtitles working when casting a video but it simple didn't work, sorry for that.

Why not v2.18.2

It needs a compileSdkVersion of at least 33

@jepiqueau
Copy link
Collaborator

@PhantomPainX Are subtitles available for standard use (without ChromeCast) ?

@jepiqueau
Copy link
Collaborator

@PhantomPainX Do you want me to merge this PR or i wait till you fix the subtitle issue

@PhantomPainX
Copy link
Contributor Author

Hey, sorry for the late.

@PhantomPainX Are subtitles available for standard use (without ChromeCast) ?

Yep, subtitles are available without chromecast. It should work as before.

@PhantomPainX Do you want me to merge this PR or i wait till you fix the subtitle issue

You can merge it now, I don't think I'll fix it any time soon.

@jepiqueau jepiqueau merged commit e2dcf60 into harmonwood:master Jan 22, 2023
@jepiqueau
Copy link
Collaborator

@PhantomPainX Can you explain me why the BackPressed method in FullscreenExoPlayerFragment.java has changed

  • from
    private void backPressed() {
        if (
            !isInPictureInPictureMode &&
            Build.VERSION.SDK_INT >= Build.VERSION_CODES.N &&
            packageManager.hasSystemFeature(PackageManager.FEATURE_PICTURE_IN_PICTURE) &&
            isPIPModeeEnabled
        ) {
            pictureInPictureMode();
        } else {
            playerExit();
        }
    }
  • to
    private void backPressed() {
      playerExit();
    }

Need your answer before publishing the new release as there is another PR which is now conflicting.

@jepiqueau
Copy link
Collaborator

@PhantomPainX I also put back some of the required files that you remove to ba able to build the plugin in Android

@PhantomPainX
Copy link
Contributor Author

PhantomPainX commented Jan 22, 2023

@PhantomPainX Can you explain me why the BackPressed method in FullscreenExoPlayerFragment.java has changed

  • from
    private void backPressed() {
        if (
            !isInPictureInPictureMode &&
            Build.VERSION.SDK_INT >= Build.VERSION_CODES.N &&
            packageManager.hasSystemFeature(PackageManager.FEATURE_PICTURE_IN_PICTURE) &&
            isPIPModeeEnabled
        ) {
            pictureInPictureMode();
        } else {
            playerExit();
        }
    }
  • to
    private void backPressed() {
      playerExit();
    }

Need your answer before publishing the new release as there is another PR which is now conflicting.

It was a personal need. I required that when pressing the back button would only exit the player and not enter in pip mode if it was enabled, I forgot to leave the original function. However I think this is the correct action when you press the back button.

Anyway it's up to you if you want to leave the original function. If you keep the original, then you need to check if the player is in Chromecast mode and just exit the player in that case

@jepiqueau
Copy link
Collaborator

@PhantomPainX thanks for answering i will put back the funcion. Is tjere à variable to test if we are in Chromecast mode?

@PhantomPainX
Copy link
Contributor Author

@PhantomPainX thanks for answering i will put back the funcion. Is tjere à variable to test if we are in Chromecast mode?

No I didn't set any as far as i remember, you can use a global variable and toggle it in castPlayer.setSessionAvailabilityListener, or use:

if (chromecast) {
    if (castContext.getCastState() == CastState.CONNECTED) {
      ...
    }
}

If you use and set a variable in castPlayer.setSessionAvailabilityListener:

onCastSessionAvailable() means the cast started
onCastSessionUnavailable() the cast ended

@jepiqueau
Copy link
Collaborator

@PhantomPainX can you test this

...
    private static final int videoStep = 10000;
    private boolean isCastSession = false;

...
            castPlayer.setSessionAvailabilityListener(
                new SessionAvailabilityListener() {
                    @Override
                    public void onCastSessionAvailable() {
                        isCastSession = true;
                        final Long videoPosition = player.getCurrentPosition();
                        if (pipEnabled) {
                            pipBtn.setVisibility(View.GONE);
                        }
                        resizeBtn.setVisibility(View.GONE);
                        player.setPlayWhenReady(false);
                        cast_image.setVisibility(View.VISIBLE);
                        castPlayer.setMediaItem(mediaItem, videoPosition);
                        styledPlayerView.setPlayer(castPlayer);
                        styledPlayerView.setControllerShowTimeoutMs(0);
                        styledPlayerView.setControllerHideOnTouch(false);
                    }

                    @Override
                    public void onCastSessionUnavailable() {
                        isCastSession = false;
                        final Long videoPosition = castPlayer.getCurrentPosition();
                        if (pipEnabled) {
                            pipBtn.setVisibility(View.VISIBLE);
                        }
                        resizeBtn.setVisibility(View.VISIBLE);
                        cast_image.setVisibility(View.GONE);
                        styledPlayerView.setPlayer(player);
                        player.setPlayWhenReady(true);
                        player.seekTo(videoPosition);
                        styledPlayerView.setControllerShowTimeoutMs(3000);
                        styledPlayerView.setControllerHideOnTouch(true);
                    }
                }
            );
...

    /**
     * Perform backPressed Action
     */
    private void backPressed() {
        if (isCastSession) {
            playerExit();
        }
        if (
            !isInPictureInPictureMode &&
            Build.VERSION.SDK_INT >= Build.VERSION_CODES.N &&
            packageManager.hasSystemFeature(PackageManager.FEATURE_PICTURE_IN_PICTURE) &&
            isPIPModeeEnabled &&
            pipEnabled
        ) {
            pictureInPictureMode();
        } else {
            playerExit();
        }

    }

It would also be nice when you do a modification to run the angular-videoplayer-app-starter it seems that some video type are not working anymore DASH MPD.
Each time i want to close a video with the Exit button (<-) i got the following error:

2023-01-23 11:19:01.720 3218-6577/com.jeep.app.ioniccapacitorvideoplayer E/BufferQueueProducer: [MediaCodec.release](id:c920000000e,api:3,p:3218,c:3218) detachBuffer: slot 0 is not owned by the producer (state = FREE)
2023-01-23 11:19:01.722 3218-6577/com.jeep.app.ioniccapacitorvideoplayer E/BufferQueueProducer: [MediaCodec.release](id:c920000000e,api:3,p:3218,c:3218) detachBuffer: slot 1 is not owned by the producer (state = FREE)
2023-01-23 11:19:01.723 3218-6577/com.jeep.app.ioniccapacitorvideoplayer E/BufferQueueProducer: [MediaCodec.release](id:c920000000e,api:3,p:3218,c:3218) detachBuffer: slot 2 is not owned by the producer (state = FREE)
2023-01-23 11:19:01.724 3218-6577/com.jeep.app.ioniccapacitorvideoplayer E/BufferQueueProducer: [MediaCodec.release](id:c920000000e,api:3,p:3218,c:3218) detachBuffer: slot 3 is not owned by the producer (state = FREE)
2023-01-23 11:19:01.726 3218-6577/com.jeep.app.ioniccapacitorvideoplayer E/BufferQueueProducer: [MediaCodec.release](id:c920000000e,api:3,p:3218,c:3218) detachBuffer: slot 4 is not owned by the producer (state = FREE)
2023-01-23 11:19:01.726 3218-6577/com.jeep.app.ioniccapacitorvideoplayer E/BufferQueueProducer: [MediaCodec.release](id:c920000000e,api:3,p:3218,c:3218) detachBuffer: slot 5 is not owned by the producer (state = FREE)
2023-01-23 11:19:01.727 3218-6577/com.jeep.app.ioniccapacitorvideoplayer E/BufferQueueProducer: [MediaCodec.release](id:c920000000e,api:3,p:3218,c:3218) detachBuffer: slot 6 is not owned by the producer (state = FREE)
2023-01-23 11:19:01.727 3218-6577/com.jeep.app.ioniccapacitorvideoplayer E/BufferQueueProducer: [MediaCodec.release](id:c920000000e,api:3,p:3218,c:3218) detachBuffer: slot 7 is not owned by the producer (state = FREE)
2023-01-23 11:19:01.727 3218-6577/com.jeep.app.ioniccapacitorvideoplayer E/BufferQueueProducer: [MediaCodec.release](id:c920000000e,api:3,p:3218,c:3218) detachBuffer: slot 8 is not owned by the producer (state = FREE)
2023-01-23 11:19:01.727 3218-6577/com.jeep.app.ioniccapacitorvideoplayer E/BufferQueueProducer: [MediaCodec.release](id:c920000000e,api:3,p:3218,c:3218) detachBuffer: slot 9 is not owned by the producer (state = FREE)
2023-01-23 11:19:01.728 3218-6577/com.jeep.app.ioniccapacitorvideoplayer E/BufferQueueProducer: [MediaCodec.release](id:c920000000e,api:3,p:3218,c:3218) detachBuffer: slot 10 is not owned by the producer (state = FREE)
2023-01-23 11:19:01.728 3218-6577/com.jeep.app.ioniccapacitorvideoplayer E/BufferQueueProducer: [MediaCodec.release](id:c920000000e,api:3,p:3218,c:3218) detachBuffer: slot 11 is not owned by the producer (state = FREE)

Can you have a look?

@jepiqueau
Copy link
Collaborator

@PhantomPainX I got the same type of error when the video reach the end

@jepiqueau
Copy link
Collaborator

@PhantomPainX The Dash mpd video is working. it was the url which were not existing anymore

@jepiqueau
Copy link
Collaborator

@PhantomPainX the error seerms to come from exoplayer itself i try ExoPlayerDemo which is giving the same error when doing a back press

@PhantomPainX
Copy link
Contributor Author

I will test your code and about the dash problem, I will check this and maybe get a fix in some way.

Anyway that demo you used has the latest version of exoplayer, so if it's a bug in their side, maybe the best solution is to downgrade and try.

It worked before?

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