简体   繁体   中英

Android MediaPlayer java.io.IOException: Prepare failed.: status=0x1, cant fix

I've tried a lot of things... but none seem to work. Most of them from here: Android MediaPlayer java.io.IOException: Prepare failed.: status=0x1

So I tried to play music using MediaPlayer in android, But the prepare always fails with the same exception. Here is my onStartCommand function:

@Override
    public int onStartCommand(Intent intent,int flags, int startId)
    {
        Toast.makeText(this, "Service on start", Toast.LENGTH_LONG).show();
        String lnk = intent.getExtras().getString("link");
        mediaPlayerM.reset();
        if(!mediaPlayerM.isPlaying())
        {
            try
            {
                mediaPlayerM.setDataSource(lnk);
                mediaPlayerM.setAudioStreamType(AudioManager.STREAM_MUSIC);
                mediaPlayerM.prepare();
            }
            catch (Exception e)
            {
                System.out.print(e.toString());
                Toast.makeText(this, e.toString(), Toast.LENGTH_LONG).show();
            }
        }
        return START_STICKY;
    }

and the onPrepared function:

public void onPrepared(MediaPlayer mp)
    {
        if(!mediaPlayerM.isPlaying())
        {
            mediaPlayerM.start();
        }
    }

So basically I try debugging, and everytime variable e (which is the exception) is the same java.io.IOException: Prepare failed.: status=0x1.

Btw, the URL I pass is: http://www.ilemon.mobi/fightnIncastle1.mp3 , which should work fine.

TL;DR: My question, is why does it throw the expectation whenever I USE the mediaPlayer.prepare() method. I pass the URL using setDataSource. and prepare should call onPrepared when it is ready to play audio... but again, the exception happens, for some reason. And I'm not sure why it happens.... that's what I'm asking. (I have all the permissions in the manifest)

Try using https://www.ilemon.mobi/fightnIncastle1.mp3 as the URL. I suspect it's something to do with non-https stream.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM