Forum Xamarin.Android
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

MediaPlayer Prepare failed. : stauts=0x1

IkeNwaoguIkeNwaogu USMember
edited December 2016 in Xamarin.Android

Hey I am following the guide for using audio here on the xamarin website. Every time I run my code I get this error : Java.IO.IOException: Prepare failed.: status=0x1. My audio file is in the assets folder and is an mp3. Does anyone know why I am getting this error?. My code is below:

public class MainActivity : Activity
        protected MediaPlayer player = new MediaPlayer();
        public void StartPlayer(string filePath)
            if (player == null)
                player = new MediaPlayer();

        protected override void OnCreate(Bundle bundle)

            // Set our view from the "main" layout resource
             SetContentView (Resource.Layout.Main);
            StartPlayer(@"c:\users\sr116\documents\visual studio 2015\Projects\WorkingWithAudio\WorkingWithAudio\Assets\Instrumental.mp3");



  • JoshuaGrassJoshuaGrass USMember

    I'm having the exact same problem. sometimes it works, some times it doesn't.

  • Hi,
    I wasted a lot of time, trying to find a solution to this issue on my side too. So I post here, just in case it is helping some people.
    My situation : I wanted to load an audio file from my assets (so not registered in my resources). I am using a similar code as Ike Nwaogu, except that I am using an AssetFileDescriptor to open my file (in my activity class code, so I have access to "Assets") :

    string path = "Audio/myfile.ogg";
    Android.Content.Res.AssetFileDescriptor afd = Assets.OpenFd(path);
    MediaPlayer soundPlayer = new MediaPlayer();
    if (afd != null)
        soundPlayer.Enabled = true;

    I was failing on the Prepare(). I tried to add the access to external storage permissions (but it did make sense since it was loaded from my assets directly, I tried just in case).

    Just by chance, by seeing other people samples on the forums, I added the afd.StartOffset, afd.DeclaredLength to the parameters:

    soundPlayer.SetDataSource(afd.FileDescriptor, afd.StartOffset, afd.DeclaredLength);

    and it worked ... I don't know if it just luck and if is going to fail again later or if there is a bug in API ...

Sign In or Register to comment.