Xamarin-Plugins icon indicating copy to clipboard operation
Xamarin-Plugins copied to clipboard

No playback (Prepare failed.: status=0x1)

Open gimenezfrg opened this issue 4 years ago • 8 comments

Hello, I'm using this component and it's working normally on several devices, but not on two devices with Android 10.

One of them is a Xiaomi Mi 9 SE, I debugged the device and got this error:


Java.IO.IOException: Prepare failed .: status = 0x1
  at Java.Interop.JniEnvironment + InstanceMethods.CallVoidMethod (Java.Interop.JniObjectReference instance, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue * args) [0x0006e] in <42748fcc36b74733af2d99408>
  at Java.Interop.JniPeerMembers + JniInstanceMethods.InvokeVirtualVoidMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue * parameters) [0x0002a] in <42748fcc36b7473382cc9407478afccd
  at Android.Media.MediaPlayer.Prepare () [0x0000a] in <7d2292394f8c488b97f5bc2a0ac0240d>: 0
  at Plugin.SimpleAudioPlayer.SimpleAudioPlayerImplementation.PreparePlayer () [0x00000] in F: \ dev \ open \ Xamarin-Plugins \ SimpleAudioPlayer \ SimpleAudioPlayer \ Plugin.SimpleAudioPlayer.Android \ SimpleAudioPlayerImplementation.cs: 139
  at Plugin.SimpleAudioPlayer.SimpleAudioPlayerImplementation.Load (System.IO.Stream audioStream) [0x000a2] in F: \ dev \ open \ Xamarin-Plugins \ SimpleAudioPlayer \ SimpleAudioPlayer \ Plugin.SimpleAudioPlayer.Android \ SimpleAudioPlayerImplementation.cs: 120
  at TagssApp.ChatTemplates.ChatMessageAudioOut.btPlayPause_Clicked (System.Object sender, System.EventArgs e) [0x00122] in D: \ _ Develop \ Github \ TagssApp \ TagssApp \ TagssApp \ TagssApp \ ChatTemplates \ ChatMessageAudioOut.xaml.cs
  --- End of managed Java.IO.IOException stack trace ---
java.io.IOException: Prepare failed .: status = 0x1
at android.media.MediaPlayer._prepare (Native Method)
at android.media.MediaPlayer.prepare (MediaPlayer.java:1327)
at crc643f46942d9dd1fff9.ImageButtonRenderer.n_onClick (Native Method)
at crc643f46942d9dd1fff9.ImageButtonRenderer.onClick (ImageButtonRenderer.java:94)
at android.view.View.performClick (View.java:7250)
at android.view.View.performClickInternal (View.java:7227)
at android.view.View.access $ 3500 (View.java:819)
at android.view.View $ PerformClick.run (View.java:27749)
at android.os.Handler.handleCallback (Handler.java:883)
at android.os.Handler.dispatchMessage (Handler.java:100)
at android.os.Looper.loop (Looper.java:224)
at android.app.ActivityThread.main (ActivityThread.java:7562)
at java.lang.reflect.Method.invoke (Native Method)
at com.android.internal.os.RuntimeInit $ MethodAndArgsCaller.run (RuntimeInit.java falso39)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:950)

Plugin.SimpleAudioPlayer.ISimpleAudioPlayer audio = Plugin.SimpleAudioPlayer.CrossSimpleAudioPlayer.Current;
var st = File.OpenRead (currentItem.Path);
audio.Load (st); **// The error happens here.**

On my virtual machine running Android 10 it works normally.

Can someone help me?

gimenezfrg avatar Sep 23 '20 03:09 gimenezfrg

The problem only happens with Xiaomi devices, as far as I could tell they don't touch .WAV

someone?

gimenezfrg avatar Nov 04 '20 23:11 gimenezfrg

I have had this problem for a while now -- everything works fine on Samsung and Pixel devices but throws this error on OnePlus, Xperia and Xiaomi devices.

aharwood2 avatar Jan 08 '21 20:01 aharwood2

I've just noticed that I have the same issue on a OnePlus while it worked just fine on other devices like Pixel 2 and Samsung

marcojak avatar Jan 16 '21 13:01 marcojak

Any updates?

vladikKBR85 avatar Feb 10 '21 06:02 vladikKBR85

I don't have access to any of these devices unfortunately.

You can try v1.5 which is using the newer Android SDK.

adrianstevens avatar Jul 17 '21 05:07 adrianstevens

Solved by adding second silent channel, thus converting mono to stereo. And everything works. Issue is not related to plugin itself

vladikKBR85 avatar Aug 05 '21 13:08 vladikKBR85

@adrianstevens, on the version 1.5 the same problem exists. @vladikKBR85, could you share your solution? I don't understand what exactly did you do?

piotrbalut avatar Aug 16 '21 07:08 piotrbalut

@vladikKBR85, could you share your solution? I don't understand what exactly did you do?

The underlying native android player fails to load monophonic sound for a some reason. I had to convert it to stereophonic sound on the server side. Using NAudio it should be something like:

using (var inputReader = new WaveFileReader(stream)){
var stereo = new MonoToStereoSampleProvider(inputReader.ToSampleProvider()); stereo.LeftVolume = 0.0f; // silence in left channel stereo.RightVolume = 1.0f; // full volume in right channel WaveFileWriter.WriteWavFileToStream(retStream, stereo.ToWaveProvider()); return retStream.ToArray(); }

vladikKBR85 avatar Aug 16 '21 12:08 vladikKBR85