Android Mediaplayer Throwing "Prepare Failed.: Status=0X1" on 2.1, Works on 2.2

Android MediaPlayer throwing Prepare failed.: status=0x1 on 2.1, works on 2.2

I do not know if this is your issue, but I just found a solution to the problem the described by Tuszy above. I could read the file I was creating from external storage but not from Cache.

The solution is that the read write permissions when writing the file are different.

Please see this excellent explanation in this blog I found.

http://blog.weston-fl.com/android-mediaplayer-prepare-throws-status0x1-error1-2147483648/

enter image description here

enter image description here

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

private void initializeMediaPlayer() {
player = new MediaPlayer();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
player.setAudioAttributes(new AudioAttributes.Builder()
.setUsage(AudioAttributes.USAGE_MEDIA)
.setContentType(AudioAttributes.CONTENT_TYPE_MUSIC)
.setLegacyStreamType(AudioManager.STREAM_MUSIC)
.build());
} else {
player.setAudioStreamType(AudioManager.STREAM_MUSIC);
}
try {
player.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
mp.start();
}
});
player.setDataSource(url);
player.prepareAsync();
} catch (Exception e) {
e.printStackTrace();
}
}

onPrepared calling in seconds.

In android 9, check this https://developer.android.com/training/articles/security-config

AndroidManifest.xml add networkSecurityConfig attributes

...
<application
android:networkSecurityConfig="@xml/network_security_config"
...>
...

in src/res/xml add network_security_config.xml file

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config cleartextTrafficPermitted="true">
<trust-anchors>
<certificates src="system" />
<certificates src="user" />
</trust-anchors>
</base-config>
</network-security-config>

MediaPlayer on Android Wear OS. Why do I get a IOException after prepare. Prepare failed status=0x1

OK I found the solution and the error. The error takes place if the url is a HTTP connection instead of a HTTPS. If the source is only accessable from a HTTP connection there are at least 2 solution.

1.) that one worked for me.
enter the following line in the manifest under application

   android:usesCleartextTraffic="true"

2.) add a network security file. info found under
https://developer.android.com/training/articles/security-config.html

that solves the problem

Android Streaming Wav Audio Error: MediaPlayer Prepare failed: status=0x1

I think you might want to take a look at: Using AudioTrack to play Wav file

Another usefull link

I have downloaded a raw stream myself and it works nicely.



Related Topics



Leave a reply



Submit