RenderHeads / UnityPlugin-AVProVideo

AVPro Video is a multi-platform Unity plugin for advanced video playback
https://www.renderheads.com/products/avpro-video/
224 stars 27 forks source link

When switching to the Mediaplayer video path on my Android build (quest 3) the app crashes. #1892

Open phileday opened 3 weeks ago

phileday commented 3 weeks ago

When switching to Media player from Exo player the app crashes immediately. Find below the Logcat when this happens. This does not happen on latest 2.x version.

OS - Android (Quest 3) Unity - 2022.3.27f1 AVPro version - 3 Video spec - N/A

Logcat information on the error

2024-06-09 20:30:58.441 23333-23351 AndroidRuntime com.Whirligig.Whirligig E FATAL EXCEPTION: UnityMain Process: com.Whirligig.Whirligig, PID: 23333 java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.Integer.intValue()' on a null object reference at android.media.MediaFormat.getInteger(MediaFormat.java:1504) at com.renderheads.AVPro.Video.Player_MediaPlayer.onPrepared(Unknown Source:282) at android.media.MediaPlayer$EventHandler.handleMessage(MediaPlayer.java:3458) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loopOnce(Looper.java:214) at android.os.Looper.loop(Looper.java:304) at com.unity3d.player.UnityPlayer$F.run(Unknown Source:24)

Ste-RH commented 2 weeks ago

@phileday Can you outline the steps you are taking for this to happen? (open/close/destroy/settings-changes/etc)

phileday commented 2 weeks ago

So the way that the player works is that on the level load it changes the AVpro render path depending what is selected from before. So before anything has loaded film wise I run this code:

    if (SelectedVideoPlugin == 1)
    {
        myMovie.PlatformOptionsWindows.videoApi = Windows.VideoApi.DirectShow;
        myMovie.PlatformOptionsAndroid.videoApi = Android.VideoApi.MediaPlayer;
    }
    if (SelectedVideoPlugin == 2)
    {
        myMovie.PlatformOptionsWindows.videoApi = Windows.VideoApi.MediaFoundation;
        myMovie.PlatformOptionsAndroid.videoApi = Android.VideoApi.ExoPlayer;
    }

    if (SelectedVideoPlugin == 4)
    {
        myMovie.PlatformOptionsWindows.videoApi = Windows.VideoApi.WinRT;
        myMovie.PlatformOptionsAndroid.videoApi = Android.VideoApi.MediaPlayer;
    }

Whirligig is for both Windows and android and you can change the renderpaths in both version so I do this at the same time.

if the render path is changed during runtime the level is reloaded (allowing everything to be unloaded) and therefore this code is run again. this currently works in AVPro 2.x

The selected render path is set in the ini file that is being read early in the start function.

Whirligig is set to Exoplayer before anything has been changed.

Let me know if I can provide any more information.

Phil

Ste-RH commented 2 weeks ago

So all components are setup on a scene/level load, then you change the video API?

Does this mean the MediaPlayer has loaded before the change? Maybe even playing?

I don't see how changing the video API after the player has been initialised can have ever worked in v2 without a complete destroy/init sequence on the MediaPlayer component. Are you 100% sure it was changing the video API? Or that you were not changing it prior to the player being created?

phileday commented 2 weeks ago

The MediaPlayer shouldn't of loaded or played anything before I change the api. The reason I reload the level is so that all media player components are destroyed and rebuilt. The object that the media player is on isn't enabled until after this has been changed. This has worked on both PC and android up until now so I'm thinking that the media player mustn't of loaded before I make this change as it's been like this without any problems for a few years now.

The one thing I haven't tried is having the media player object set to "Media player" instead of "Exo Player" before it gets turned on so that I know that it's just crashing on load and not the change of API. I can try that this evening and let you know what the result it :)

Ste-RH commented 2 weeks ago

The player (plugin side) gets made on the line:

_player = Native.AVPPluginMakePlayer(_playerSettings);

...in PlatformMediaPlayer.cs

Maybe put a log there and see what order things are done in (you setting the video API) ? If you are going to change the video API, then it has to be passed in to that constructor in the options parameter.

phileday commented 2 weeks ago

A little bit more information on this. It isn't changing the video path that's causing the crash. It's a soon as a video is loaded. It crashes. I basically made a version on my player where it was already set to MediaPlayer API and the player crashed as soon as I loaded a file.

I might be able to strip the project down to just the player and loading a file. It might be one of the settings in AVPro that is causing it so if I can manage that I'll send it over.

Phil

Chris-RH commented 2 weeks ago

Thanks, that'll be super helpful :)

On Wed, 12 Jun 2024 at 18:47, phileday @.***> wrote:

A little bit more information on this. It isn't changing the video path that's causing the crash. It's a soon as a video is loaded. It crashes. I basically made a version on my player where it was already set to MediaPlayer API and the player crashed as soon as I loaded a file.

I might be able to strip the project down to just the player and loading a file. It might be one of the settings in AVPro that is causing it so if I can manage that I'll send it over.

Phil

— Reply to this email directly, view it on GitHub https://github.com/RenderHeads/UnityPlugin-AVProVideo/issues/1892#issuecomment-2163595939, or unsubscribe https://github.com/notifications/unsubscribe-auth/AYRROUIGENKLI4A6W5S6SQDZHCCTTAVCNFSM6AAAAABJBEKWG2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCNRTGU4TKOJTHE . You are receiving this because you are subscribed to this thread.Message ID: @.***>

Chris-RH commented 5 days ago

Have you had any luck with this?

phileday commented 5 days ago

Sorry I've not had a chance to retest yet. I managed to get ill from a Tescos sandwich and I've been recovering since but I'm getting back into testing over the next few days so I can retest then.

Actually I did find a video that caused the player to crash with v3 but not v2. I'll use that to test as well and provide a link. It's a blender animation so there will be no problem sharing it.

Chris-RH commented 4 days ago

I'm sorry that you've been poorly. No rush, I was just checking in on you :)