Skip to content

App crashes on low android level **Java.IO.IOException:** 'Prepare failed.: status=0x1' #47

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

Closed
ertandk opened this issue Feb 16, 2023 · 7 comments

Comments

@ertandk
Copy link

ertandk commented Feb 16, 2023

Hello, I managed to play the sound by watching the video on youtube (android 10.11), but,
On an old device (android 6.0.1) etc. It directly causes my application to crash.
Its output is;

[MediaPlayer] error (1, -2147483648)
**Java.IO.IOException:** 'Prepare failed.: status=0x1'
[mono-rt] [ERROR] FATAL UNHANDLED EXCEPTION: Java.IO.IOException: Prepare failed.: status=0x1
[mono-rt] at Java.Interop.JniEnvironment.InstanceMethods.CallVoidMethod(JniObjectReference instance, JniMethodInfo method, JniArgumentValue* args) in /Users/runner/work/1/s/xamarin-android/external/Java.Interop/src/ java.Interop/obj/Release/net7.0/JniEnvironment.g.cs:line 11884
[mono-rt] at Java.Interop.JniPeerMembers.JniInstanceMethods.InvokeVirtualVoidMethod(String encodedMember, IJavaPeerable self, JniArgumentValue* parameters) in /Users/runner/work/1/s/xamarin-android/external/Java/Interop Java.Interop/Java.Interop/JniPeerMembers.JniInstanceMethods_Invoke.cs:line 66
[mono-rt] at Android.Media.MediaPlayer.Prepare() in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/obj/Release/net7.0/android-33/mcw /Android.Media.MediaPlayer.cs:line 3748
[mono-rt] at Plugin.Maui.Audio.AudioPlayer..ctor(Stream audioStream)
[mono-rt] at Plugin.Maui.Audio.AudioManager.CreatePlayer(Stream audioStream)
var player = audioManager.CreatePlayer(await FileSystem.OpenAppPackageFileAsync("sound.wav"));
            player.Loop = true;
            player.Play();
}

What is the solution? I want to use this library.

@ertandk
Copy link
Author

ertandk commented Feb 16, 2023

@jfversluis

@jfversluis
Copy link
Owner

jfversluis commented Feb 16, 2023

Could you maybe add a reproduction project for this so I can have a look?

The error doesn't have a lot of info, but this line: **Java.IO.IOException:** 'Prepare failed.: status=0x1' makes me think that it either can't find the file that you specify or you didn't request the necessary permissions.

Also, just to set expectations: I understand this might be urgent to you, I appreciate that, however I may have different priorities than you. I cannot make any promises about if and when this will be fixed. This project is a community effort, which we are not being paid for.

@jfversluis jfversluis changed the title Urgent please App crashes on low android level **Java.IO.IOException:** 'Prepare failed.: status=0x1' App crashes on low android level **Java.IO.IOException:** 'Prepare failed.: status=0x1' Feb 16, 2023
@ertandk
Copy link
Author

ertandk commented Feb 16, 2023

Could you maybe add a reproduction project for this so I can have a look?

The error doesn't have a lot of info, but this line: **Java.IO.IOException:** 'Prepare failed.: status=0x1' makes me think that it either can't find the file that you specify or you didn't request the necessary permissions.

Also, just to set expectations: I understand this might be urgent to you, I appreciate that, however I may have different priorities than you. I cannot make any promises about if and when this will be fixed. This project is a community effort, which we are not being paid for.

I'm afraid that the emulator does not give an error, most likely if I upload an example, you will not get an error.
Android 6.0.1 does not crash on emulators in versions like Android 5.0, but it crashes on my physical device.
In a few google searches, they mention that it crashes on non-samsung devices, I don't know how true it is.

Can I read the sound.wav file any other way?

@jfversluis
Copy link
Owner

Sure, you can use System.IO.ReadAllBytes and turn that into a stream and use that as well, but I suspect that won't be much different.

You might want to try and move this line: await FileSystem.OpenAppPackageFileAsync("sound.wav") to it's own variable. So for instance: var soundFile = await FileSystem.OpenAppPackageFileAsync("sound.wav"); then debug through it and see if that actually works.

Also double-check that you added the file in the Resources/Raw folder and the BuildAction is set the MauiAsset.

As mentioned: I have a feeling that it either can't find the file or it can't be opened due to a permissions issue.

@ertandk
Copy link
Author

ertandk commented Feb 16, 2023

Sure, you can use System.IO.ReadAllBytes and turn that into a stream and use that as well, but I suspect that won't be much different.

You might want to try and move this line: await FileSystem.OpenAppPackageFileAsync("sound.wav") to it's own variable. So for instance: var soundFile = await FileSystem.OpenAppPackageFileAsync("sound.wav"); then debug through it and see if that actually works.

Also double-check that you added the file in the Resources/Raw folder and the BuildAction is set the MauiAsset.

As mentioned: I have a feeling that it either can't find the file or it can't be opened due to a permissions issue.

<MauiAsset Include="Resources\Raw\**" LogicalName="%(RecursiveDir)%(Filename)%(Extension)" />
attached,
now I tried it on different physical android 10, android 11 devices, it didn't crash.
On my old device this crashes,
var soundFile = await FileSystem.OpenAppPackageFileAsync("sound.wav"); crashing is happening here.

adrianstevens/Xamarin-Plugins#75 (comment) I seem to have the same problem as people here.

I was planning to finish the application, I was very upset when I threw it on my old device and observed this problem :(

@jfversluis
Copy link
Owner

Looks like there was also a workaround provided: adrianstevens/Xamarin-Plugins#75 (comment)

It seems like those device cannot handle a certain type of audio files.

I'm afraid there is not much we can do about that with our code. This has to do with what a device supports for the audio. I hope you can figure out how to make it work, please let us know if you do!

@jfversluis jfversluis closed this as not planned Won't fix, can't repro, duplicate, stale Feb 16, 2023
@ertandk
Copy link
Author

ertandk commented Feb 16, 2023

The phone does not support the wav format.
Audio playback with m4a format is successful.
Thank you so much for your support and suggestions!
I was about to go crazy :)

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

No branches or pull requests

2 participants