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/
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
How to Display Input Errors in Popup
How to Create Custom UI for Android Mediacontroller
Navigation Drawer Semi-Transparent Over Status Bar Not Working
Android Persistence Room: "Cannot Figure Out How to Read This Field from a Cursor"
Jni and Gradle in Android Studio
How to Hide a Button Programmatically
How to Add a Fast-Scroller to the Recyclerview
How to Attach the Android Support Library Source in Eclipse
How to Change Background Color in Android App
Start an Activity from a Fragment
Disconnect a Bluetooth Socket in Android
Navigation Drawer: Set as Always Opened on Tablets
Difference Between APK (.Apk) and App Bundle (.Aab)
Memory Leaks with Custom Font for Set Custom Font
Toggle Button Using Two Image on Different State
Trying to Get the Display Size of an Image in an Imageview
What Is the Use of the Res/Values/Public.Xml File on Android