MediaPlayer Bug in iOS 16

Hi Folks,

we’re encountering problems with the implementation of the media player framework for the unreal engine and iOS16. What the guys at epic are doing is basically calling

(AVPlayerItem* PlayerItem;) [[PlayerItem asset] loadValuesAsynchronouslyForKeys:@[@“tracks”] completionHandler:^ […]

to load the local asset and than (AVPlayer* MediaPlayer;) [MediaPlayer replaceCurrentItemWithPlayerItem : PlayerItem];

to set the asset and

[MediaPlayer prerollAtRate:1.0f completionHandler:^(BOOL bFinished) […]

to start preloading. At this point the player doesn’t call the completionHandler anymore reliable since the release of iOS 16. Before everything was working flawless, but now most of the time the asset loading fails without errors. Any thoughts what might have changed with ios16? Probably it’s due to some threading issue. Any help highly welcome!

1 Like

Oh my god, I just have the same problem, do you work on unreal 4.27 or 5?
I can’t find a workaround for this one since it’s so random :confused:

At least, we’re not alone :smiley: It’s a custom build of the 4.26 branch. We still try to alter the AVMediaPlayer Plugin on a few lines, but so far it really doesn’t look very promising…

1 Like

Could you check if this helps in your project too. It basically disables the prerolling in the avfmediaplayer. In our test project it was working, in the final project, it was still misbehaving, so it might not fix completely.

Copy the Plugin from the Engine to your Project Plugins Folder
C:\Program Files\Epic Games[VERSION]\Engine\Plugins\Media\AvfMedia

Than replace the AvfMedia\Source\AvfMedia\Private\Player\AvfMediaPlayer.cpp with the attached file.

AvfMediaPlayer.cpp (29.8 KB)

Afterwards delete the Plugin Intermediate and Binaries Folder and let the engine rebuild it.

2 Likes

Thx for the update.
Do I need to rebuild Unreal to make this change, because we actually use the default engine downloaded with the epic launcher.

No, it’s an official plugin, but if you copy it to your project plugin folder, it should recompile.

Thank you for your hard work.
Your solution may fix our project’s iOS 16 crash and media related bugs.
Thanks again

Hi, did you slove the issue? Thanks

Yes, the altered Plugin fixes it. Since the newest MacOS version the MediaPlayer is broken there too, but can be fixed exactly the same way than on iOS. Just remove the if #if PLATFORM_MAC code block and the #else/#endif and it should work.

1 Like

Hi everyone.
I was going crazy on these video bugs until I found your posts. Thanks so much!
I followed the instructions but now I am getting these errors while building for iOS.
Do you have a solution for that, too? I would really appreciate it! ;-D


[2/9] Compile Module.AvfMediaFactory.cpp
UATHelper: Packaging (iOS):     In file included from C:\***\Plugins\AvfMedia\Intermediate\Build\IOS\UE4\Shipping\AvfMedia\Module.AvfMedia.cpp:3:
UATHelper: Packaging (iOS):     C:\***\Plugins\AvfMedia\Source\AvfMedia\Private\Player\AvfMediaPlayer.cpp:396:67: error: use of undeclared identifier 'GetAvfMediaPlayerDebugData'
UATHelper: Packaging (iOS):             UE_LOG(LogTemp, Warning, TEXT("State of AVFMediaPlayer is %s"), *GetAvfMediaPlayerDebugData());
UATHelper: Packaging (iOS):                                                                              ^
UATHelper: Packaging (iOS):     C:\***\Plugins\AvfMedia\Source\AvfMedia\Private\Player\AvfMediaPlayer.cpp:614:9: error: use of undeclared identifier 'GetAvfMediaPlayerDebugData'
UATHelper: Packaging (iOS):             return GetAvfMediaPlayerDebugData();
UATHelper: Packaging (iOS):                    ^
PackagingResults: Error: use of undeclared identifier 'GetAvfMediaPlayerDebugData'
PackagingResults: Error: use of undeclared identifier 'GetAvfMediaPlayerDebugData'
UATHelper: Packaging (iOS):     C:\***\Plugins\AvfMedia\Source\AvfMedia\Private\Player\AvfMediaPlayer.cpp:623:26: error: out-of-line definition of 'GetAvfMediaPlayerDebugData' does not match any declaration in 'FAvfMediaPlayer'
UATHelper: Packaging (iOS):     FString FAvfMediaPlayer::GetAvfMediaPlayerDebugData() const
UATHelper: Packaging (iOS):                              ^~~~~~~~~~~~~~~~~~~~~~~~~~
PackagingResults: Error: out-of-line definition of 'GetAvfMediaPlayerDebugData' does not match any declaration in 'FAvfMediaPlayer'
UATHelper: Packaging (iOS):     3 errors generated.

Ah, sorry about that. We added a new function for further debugging. Just delete the whole GetAvfMediaPlayerDebugData function from the cpp file. The error occures because the function is not defined in the AvfMediaPlayer.h file. Or use the attached plugin, it’s the one we are using currently.
AvfMedia.zip (46.4 KB)

1 Like

Hi.

how can i build the plugin on a mac? I always get an error message: …could not be compiled. Try rebuilding from source manually.

Thanks in advance!

This worked, thank you!