Game crashing when Android MediaPlayer fails to open URL

I am building for Gear VR (so, Android ETC2). At the beginning of my game, I have a MediaPlayer starting in auto, opening a file with a URL. If the device is connected to W-Fi when I start the game, everything works fine; if it is not connected, the game crashes and the Home screen appears.

Not sure it is related, but the only information that I found in the logcat that could be related to the problem is:

05-11 15:42:14.241  3088 16735 V MediaPlayerService: [57] notify (0xec6d6b00, 100, 1, -1005)
05-11 15:42:14.241  3088 16735 E NuPlayer: Network errror is occured (-1004)
05-11 15:42:14.241  3088 16735 D NuPlayer: set mHTTPStreaming = FALSE
05-11 15:42:14.241 16686 16698 V MediaPlayer: message received msg=100, ext1=1, ext2=-1005
05-11 15:42:14.241 16686 16698 E MediaPlayer: error (1, -1005)
05-11 15:42:14.241 16686 16698 V MediaPlayer: signal application thread
05-11 15:42:14.241 16686 16702 V MediaPlayer: prepare complete - status=1
05-11 15:42:14.241 16686 16702 W System.err: java.io.IOException: Prepare failed.: status=0x1
05-11 15:42:14.241 16686 16702 W System.err: 	at android.media.MediaPlayer._prepare(Native Method)
05-11 15:42:14.241 16686 16702 W System.err: 	at android.media.MediaPlayer.prepare(MediaPlayer.java:1369)
05-11 15:42:14.251 16686 16702 D UE4     : Assertion failed: false && "Java JNI call failed with an exception." [File:D:\BuildFarm\buildmachine_++UE4+Release-4.11\Engine\Source\Runtime\Core\Private\Android\AndroidJava.cpp] [Line: 139] 
05-11 15:42:14.251 16686 16702 D UE4     : libUE4.so!FDebug::LogAssertFailedMessage(char const*, char const*, int, wchar_t const*, ...) 
05-11 15:42:14.251 16686 16702 D UE4     : libUE4.so!void FJavaClassObject::CallMethod<void>(FJavaClassMethod, ...) 
05-11 15:42:14.251 16686 16702 D UE4     : libUE4.so!FJavaAndroidMediaPlayer::Prepare() 
05-11 15:42:14.251 16686 16702 D UE4     : libUE4.so!FAndroidMediaPlayer::Open(FString const&) 
05-11 15:42:14.251 16686 16702 D UE4     : libUE4.so!non-virtual thunk to FAndroidMediaPlayer::Open(FString const&) 
05-11 15:42:14.251 16686 16702 D UE4     : libUE4.so!UMediaPlayer::InitializePlayer() 
05-11 15:42:14.251 16686 16702 D UE4     : libUE4.so!UMediaPlayer::PostLoad() 
05-11 15:42:14.251 16686 16702 D UE4     : libUE4.so!UObject::ConditionalPostLoad() 
05-11 15:42:14.251 16686 16702 D UE4     : libUE4.so!EndLoad() 
05-11 15:42:14.251 16686 16702 D UE4     : libUE4.so!LoadPackageInternal(UPackage*, wchar_t const*, unsigned int, FLinkerLoad*, TSet<FName, DefaultKeyFuncs<FName, false>, FDefaultSetAllocator>&, IAssetRegistryInterface*) 
05-11 15:42:14.251 16686 16702 D UE4     : libUE4.so!LoadPackageInternal(UPackage*, wchar_t const*, unsigned int, FLinkerLoad*) 
05-11 15:42:14.251 16686 16702 D UE4     : libUE4.so!LoadPackage(UPackage*, wchar_t const*, unsigned int) 
05-11 15:42:14.251 16686 16702 D UE4     : libUE4.so!UEngine::LoadMap(FWorldContext&, FURL, UPendingNetGame*, FString&) 
05-11 15:42:14.251 16686 16702 D UE4     : libUE4.so!UEngine::Browse(FWorldContext&, FURL, FString&) 
05-11 15:42:14.251 16686 16702 D UE4     : libUE4.so!UGameInstance::StartGameInstance() 
05-11 15:42:14.251 16686 16702 D UE4     : libUE4.so!UGameEngine::Init(IEngineLoop*) 
05-11 15:42:14.251 16686 16702 D UE4     : libUE4.so!FEngineLoop::Init() 
05-11 15:42:14.251 16686 16702 D UE4     : libUE4.so!AndroidMain(android_app*) 
05-11 15:42:14.251 16686 16702 D UE4     : libUE4.so!android_main() 
05-11 15:42:14.251 16686 16702 D UE4     : libUE4.so![Unknown]() 
05-11 15:42:14.251 16686 16702 D UE4     : libc.so![Unknown]() 
05-11 15:42:14.251 16686 16702 D UE4     : libc.so![Unknown]() 
05-11 15:42:14.251 16686 16702 D UE4     : [2016.05.11-13.42.14:258][  0]Assertion failed: Assertion failed: false && "Java JNI call failed with an exception." [File:D:\BuildFarm\buildmachine_++UE4+Release-4.11\Engine\Source\Runtime\Core\Private\Android\AndroidJava.cpp] [Line: 139] 
05-11 15:42:14.251 16686 16702 D UE4     : [2016.05.11-13.42.14:259][  0]LogWindows: FAndroidMisc::RequestExit(1)
05-11 15:42:14.251 16686 16702 I art     : System.exit called, status: 0
05-11 15:42:14.251 16686 16702 I AndroidRuntime: VM exiting with result code 0, cleanup skipped.

EDIT: after the request from , I added some details. You can find attached the UEgame logs and logcat logs. You can also find a simplified version of my level blueprint before and after the ā€œisValidā€ suggestion.

Blueprints before:

Blueprints after:

Here are the steps to reproduce my problem:

  1. Create a new project using the First Person Template. Create an empty scene or use the default one.
  2. Create a new MediaPlayer in the content browser. Create the texture and the material as usual. Apply the material to a mesh in the scene. Everything is set as in the documentation: [Media Framework in Unreal Engine | Unreal Engine 5.1 Documentation][3] , but donā€™t use a movie file imported in the content browser; instead, use an URL (the ones starting with ā€œhttp : / /ā€ ) in the ā€œsourceā€ field of the Media Player. I cannot give you the file for copyright reasons, but the file Iā€™m pointing at is an mp4 movie with H.264 encoding, frame rate 25, resolution 1920x1080.
  3. Add a reference to the Media Player in the level blueprints and set the Media Player to play on begin, as shown in the blueprints attached.
  4. Setup, package and install the project for the GearVR as described in the documentation ([https://docs.unrealengine.com/latest/INT/Platforms/GearVR/QuickStart/index.html][4])
  5. Disable any kind of internet / Wi-Fi connection on the Android device.
  6. Start the app. If the app is launched in the Gear VR, after a black screen the Oculus Home appears; if the app is launched in debug mode while connected to the pc, the app crashes (it can still be found in the list of opened apps) and the phone home screen appears.

[UE4game logs][5]

[Logcat][6]

so. use a condition to check whether URL is valid then open that.
your game does what it must when trying to access to invalid memory

What do you mean by ā€œvalidā€? The URL is valid, but of course I will not be able to connect, if there is not connection. How can I check if an URL is ā€œvalidā€, i.e. if there is connection or not, in blueprint or C++? Still, I donā€™t think that ā€œthe app crashes without a chance to recover or detect failureā€ is an acceptable behaviour.

Hi Ocramot,

Do you get the crash of the application only in the GearVR or does this happen when you package a normal Windows project as well?

As Saeedc mentioned, if you do a ā€œis validā€ check before the video do you still get the crash?

Some things Iā€™ll need to continue:

  • Crash logs from your Android Device running the app when it crashes. You can use the Android Monitor tool to do this. (details below if youā€™re not sure).
  • Logs from the project folder when it crashes (these can be found on the device storage > UE4Game > [Your Project Name] > the logs should be in this folder somewhere)
  • Iā€™ll need your full list of steps to setup and reproduce on my end. If you have a simple project you can provide that reproduces this that would be even more helpful.

Using Android Monitor App.

  • Go to C:\NVPack\android-sdk-windows\tools
  • run the Monitor.bat file
  • Connect your device to your PC (youā€™ll need to have the Android in Developer Mode for the GearVR services so that you donā€™t need the headset)
  • Run the app and get the crash to happen.
  • Save the logs and upload here in a text file

Thank you!

1 Like

Hi , thank you for your help.

Yes, the crash happens only in the Gear VR: I tried to package for Windows and it doesnā€™t crash (but the MediaPlayer->Play block in the blueprints actually outputs a ā€œfalseā€ boolean result).

Iā€™m still not sure what you and saeedc mean by ā€œisValidā€: the Mediaplayer is a valid object, the object referencing it are already present in the scene when I call it, itā€™s just that the URL canā€™t be opened if the internet connection fails. Anyway I updated my question with my level blueprints (simplified), before and after adding the ā€œisValidā€ block; tell me if I got what you mean. I also updated my question attaching the log files that you requested. I donā€™t have a simple project to reproduce the error, but I updated the questions with the steps to reproduce the problem.

Thank you for all your work!

Just to let you know Iā€™ve been able to get the crash on my end now. Iā€™m still working through some things to get it reported and look into it because there was some other wonky things going on too. I do have a feeling some of this will not be an issue when 4.13 comes though since the Media Framework is getting an overhaul, but I canā€™t be for sure since itā€™s still in development.

Also I want to note that this is note specific to GearVR and crashes with any Android project that Iā€™ve tried. I also get the video to display for a brief moment before it crashes. Iā€™ll update you soon once Iā€™ve had more time to delve in and get a ticket in. Thanks for your patience and help with the setup.

Awesome! Thank you really much for your support.

Do you know about any workaround I could implement in the meantime? Like a check connection, a try/catch-like structure, or something else?

If I could find this media player in the github code, ID like to contribute to the solution myself. :slight_smile:

Iā€™m not sure of a workaround aside from not using the web URL for the media player. If the video is local it works as I would expect. The web URL seems to just crash on launch for me regardless of it being checked or not.

Iā€™m also not sure where the github portion of the code is or if itā€™s even been put in yet. Check for any submissions from GMPreussner. Max is doing the leg work for the media framework overhaul.

Hey Ocramot,

Thanks for your patience while I was looking into this.

I think this may actually be fixed. I was able to get this to work on the GearVR Note4 with our latest Preview 5 build that is available in the launcher.

Can you try this build and see if you get the same results in a blank scene.

Try with your streaming video link and see if it works. If itā€™s giving any issue feel free to try the one from my personal site here: http://cloud2.snappages.com/3506b5337de1bf72a69f274f6dc6502d731ffc76/Default_Startup.mp4

I did this with a blank test scene, and using the EditorPlane (engine content folder).

Give that a shot and let me know how it goes on your end.

Thanks!

Hello, sorry it took me so long to reply. Unfortunately, I still have this issue. I cloned my project from 4.11.2 to Preview 5, and then tried to build it with the preview, and now also with the stable release recently available. I still get the exception on the MediaPlayer.prepare(). I attach my log, but it seems quite similar to the previous one:

I also tried with a new project from scratch, created in UE4.12.0, with the FirstPersonTemplate; I added an EditorPlane with the MediaPlayer pointing to your test URL, and Level Blueprints set to play it on BeginPlay. The project worked if the phone was connected to the Wi-Fi, and it crashed if it wasnā€™t. I attach the logs for this last case: Application logs, ADB logs.

Iā€™ve submitted UE-32029 for this one to be looked into. Be aware that there is some overhaul coming for the Media Player assets and as this work progresses it may negate this issue altogether.

Thanks!

Ok, Iā€™ll wait for the next release then.

Thank you again for your awesome work.

Hey ocramot,

I gave this another go today to see if I could at the very least find a workaround for you, but unfortunately, I was unsuccessful. However, I did find a plugin that works with binary and code builds that may be useful for you in the future.

Here you can download the Binary plugin and put in your xx/Engine/Plugins folder.

There isnā€™t any node in Blueprints that allows you to check internet connection, but this plugin does! Once you add it to the folder you can go to Edit > Plugins > Misc > Enable Mobile Utils > Restart the editor

Then in your Blueprint you can search for ā€œCheck Internet Connectionā€ node. This simply returns a true/false value that can be plugged into a branch node to check the internet connection.

All this being said, it doesnā€™t work with media textures and the crash still occurs. So what this tells me is there is some check happening before it loads the project/level that is causing the real issue, but in the future, if you need something that can check whether you have internet access or not, once the bug is fixed with the crashing this would be a good little plugin to have that functionaltiy.

Sorry I couldnā€™t be more help right away with this or have a direct workaround other than having a local video to load in the project itself.

Awesome! Thank you for your support, very appreciated.
I will try ASAP some kind of workaround, like I could have the texture point to a small ā€˜placeholderā€™ video with black screen in the content folder, then check for connection, and if the result is true, call the changeURL node in the blueprint and then play. Will write here if it worked.

To be clear, it didnā€™t work for me because it seems like there is something checking the network as the app loads that is actually causing the crash, but once the fix is in for the media URL crashing this little addition here should at least let you check internet connection and determine if the video should play or use a placeholder. Sorry if I mislead to make it seem like it fixed. I really hoping this would have been a good workaround for this particular crash though.