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

Android on OnMediaPlayerEvent the event MediaPlayerEvent.EventType.ReadyToPlay never happens. #1846

Closed phileday closed 1 week ago

phileday commented 1 month ago

In my player I listen out for 3 events to then process the video:

MediaPlayerEvent.EventType.ReadyToPlay MediaPlayerEvent.EventType.FirstFrameReady MediaPlayerEvent.EventType.MetaDataReady

and once all three have happened I then process the video. This insures that I can access file knowing it's fully loaded.

On Android MediaPlayerEvent.EventType.ReadyToPlay never occurs. This isn't a massive problem as I can just test for the other two but I though it was worth reporting. This also happens on both AVPro 2/3

OS - Android (Quest 3) Unity - 2022.3.27f1 AVPro version - 3 Video spec - N/A issue happens on all videos

Chris-RH commented 1 month ago

That's weird. It definitely used to occur (https://github.com/RenderHeads/UnityPlugin-AVProVideo/issues/1179). Is this both Android mediaplayer and Exoplayer?

phileday commented 1 month ago

I noticed it with Exoplayer for sure as that's what I test with. I'm pretty sure it was true for Mediaplayer also but I would have to double check that later.

I can make a build of my app with debugging for the events if that would help.

edward-jones-wi commented 1 month ago

I also have this issue. ReadyToPlay and FirstFrameReady are not called on Android Builds running on both Google Pixel 6 and Xiaomi Pad 6.

Platform: Android Unity Version: 2022.3.24f1 AVPro: v3 trial

Chris-RH commented 1 month ago

Are you using autoplay? ReadyToPlay isn't called if you enable autoplay. I've tested on my S9 with the mediaplayer demo scene and I'm getting both ReadyToPlay and FirstFrameReady. I'm using Unity 2021. I'll retest with 2022.

phileday commented 1 month ago

Hi I actually turn on auto play depending on the users settings (play on load of media). I think most of the time it's on though so that would explain why it's not appearing. Is this intended? ultimately What I'm looking for is an event call that guarantees that all the info I need to request is available. In my case all the meta data, the resolution, audio tracks, number of audio channels on track, subtitle tracks, duration. In the past I didn't use the event call as I wasn't familiar with it so I would use a coroutine to delay the reading of all the data. After I've implemented the event system now the delay is mostly unnecessary however I do still delay before reading depending on the video path. Media Foundation I delay 20 ticks before reading all the data and WinRT I delay 150 ticks as I've found it wouldn't always read the resolution correctly. On Android I delay 20 ticks on both Exoplayer and Mediaplayer. Hope that helps. Phil Twitter - https://twitter.com/whirligigxyzBloghttp://www.whirligig.xyz/blogYoutubehttps://www.youtube.com/channel/UC1MI0yclkwQjWjLw5bviXtg

On Tuesday, 14 May 2024 at 09:58:08 BST, Chris-RH ***@***.***> wrote:  

Are you using autoplay? ReadyToPlay isn't called if you enable autoplay. I've tested on my S9 with the mediaplayer demo scene and I'm getting both ReadyToPlay and FirstFrameReady.

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

edward-jones-wi commented 1 month ago

Are you using autoplay? ReadyToPlay isn't called if you enable autoplay. I've tested on my S9 with the mediaplayer demo scene and I'm getting both ReadyToPlay and FirstFrameReady. I'm using Unity 2021. I'll retest with 2022.

No autoplay is always false in my project.

Chris-RH commented 1 month ago

Hi @phileday,

You should try FirstFrameReady instead.

Chris-RH commented 1 month ago

@edward-jones-wi,

Which events are you getting in the run up to playback?

edward-jones-wi commented 1 month ago

I only get StartedBuffering and FinishedBuffering

Chris-RH commented 1 month ago

@edward-jones-wi

So if you put this script in your project, with autoplay disabled, you should get events such as ReadyToPlay, MetaDataReady and FirstFrameReady? Could you do this in a new project and provide a full logcat please

WI-Lee commented 1 month ago

Hi @Chris-RH,

I work with @edward-jones-wi so I've been helping to investigate this issue.

I tested this in a blank project using the Demo_MediaPlayer scene and the events fire correctly. After some further testing I have found the issue is related to the Android "file offset" feature. We use this in our project because all of our videos are loaded from Android Asset Packs.

I have created a test video (attached) using the instructions found in the documentation: copy /b BigBuckBunny-360p30-H264.mp4.meta + BigBuckBunny-360p30-H264.mp4 OffsetTest.mp4

https://github.com/RenderHeads/UnityPlugin-AVProVideo/assets/57184727/6b5050d5-5985-4cd1-a726-4dfa7c042fa7

If I use this video in the demo scene and set the offset to 144 bytes (the size of the meta file), it fails to play on device and these are the only events that appear in the log:

[AVProVideo] Initialising AVPro Video v3.0.0 (native plugin v3.0.0-trial) on Mali-G78/Vulkan 1.1.0 [0x0b800000] (MT True) on Android
[AVProVideo] Opening jar:file:///data/app/~~Kzecu6P3CNgohsgoFkYyeA==/com.DefaultCompany.AVProImport-xj0xPGJ6dNV2QT4RZ-feZg==/base.apk!/assets/AVProVideoSamples/OffsetTest.mp4 (offset 144) with API ExoPlayer
MediaPlayer MediaPlayer generated event: StartedBuffering
MediaPlayer MediaPlayer generated event: FinishedBuffering

It seems to me like the native plugin is just ignoring the specified offset and trying to play from byte 0.

Cheers, Lee

Chris-RH commented 1 month ago

Ahh, ok, that's interesting, thanks. Will look into that.

Ste-RH commented 3 weeks ago

Hi @Chris-RH,

I work with @edward-jones-wi so I've been helping to investigate this issue.

I tested this in a blank project using the Demo_MediaPlayer scene and the events fire correctly. After some further testing I have found the issue is related to the Android "file offset" feature. We use this in our project because all of our videos are loaded from Android Asset Packs.

I have created a test video (attached) using the instructions found in the documentation: copy /b BigBuckBunny-360p30-H264.mp4.meta + BigBuckBunny-360p30-H264.mp4 OffsetTest.mp4

OffsetTest.mp4 If I use this video in the demo scene and set the offset to 144 bytes (the size of the meta file), it fails to play on device and these are the only events that appear in the log:

[AVProVideo] Initialising AVPro Video v3.0.0 (native plugin v3.0.0-trial) on Mali-G78/Vulkan 1.1.0 [0x0b800000] (MT True) on Android
[AVProVideo] Opening jar:file:///data/app/~~Kzecu6P3CNgohsgoFkYyeA==/com.DefaultCompany.AVProImport-xj0xPGJ6dNV2QT4RZ-feZg==/base.apk!/assets/AVProVideoSamples/OffsetTest.mp4 (offset 144) with API ExoPlayer
MediaPlayer MediaPlayer generated event: StartedBuffering
MediaPlayer MediaPlayer generated event: FinishedBuffering

It seems to me like the native plugin is just ignoring the specified offset and trying to play from byte 0.

Cheers, Lee

A FileOffset bug was fixed in v3.0.2 @WI-Lee

WI-Lee commented 3 weeks ago

I just tried the demo scene again using v3.0.2 (I assume #1881 is the relevant issue here).

If I specify the offset in the inspector, the video plays correctly now. However, it still doesn't work if I specify the offset programmatically, e.g:

mediaPlayer.PlatformOptionsAndroid.fileOffset = 144;
mediaPlayer.OpenMedia(MediaPathType.AbsolutePathOrURL, path, true);

It seems to always use the initial offset and ignore any changes (we reuse the same MediaPlayer instance for multiple videos).

Ste-RH commented 3 weeks ago

Ok, thanks for checking. Will take another look here doing it via script.

Ste-RH commented 3 weeks ago

A fix for this will be in the next release (v3.0.3).

Chris-RH commented 2 weeks ago

AVPro Video version 3.0.3 has been released. Please let us know if it has not fixed your issue.