when i use MediaPlayer playing .mp3 file,the system will report error log:
Prepare failed.: status=0xFFFFFF8E
but the playing music is normal,there is not exception.
And according to my observations,as if it come out only in relatively high ROM version,such as 4.0,in 2.3 there is no error.
What is the reason, how to solve?
Related
A Google audio player code sample that successfully plays mp3 audio from an online stream fails as soon as the project is migrated to AndroidX.
I'm attempting to follow the best practices in building a Media Player app as detailed here: https://developer.android.com/guide/topics/media-apps/audio-app/building-an-audio-app
At the bottom of this page is a link to this sample code: https://github.com/googlesamples/android-MediaBrowserService/
This sample creates a simple media player app that plays local mp3 files, rather than a stream.
The smallest possible change I can make to the sample so that it plays a stream rather than a file is to change the following in com.example.android.mediasession.service.players.MediaPlayerAdapter:
AssetFileDescriptor assetFileDescriptor = mContext.getAssets().openFd(mFilename);
mMediaPlayer.setDataSource(
assetFileDescriptor.getFileDescriptor(),
assetFileDescriptor.getStartOffset(),
assetFileDescriptor.getLength());
to
mMediaPlayer.setDataSource("http://109.228.17.230:80/");
This works successfully. The stream plays when the Play button is pressed.
However this code sample has not been migrated to AndroidX. It is still using support library v27.0.2. I have successfully migrated the code sample to AndroidX in Android Studio, and confirmed that after doing this the sample app still successfully opens and plays local mp3 files.
If however, I make the above code change after migrating the project to AndroidX, AndroidX, MediaPlayer.prepare() fails with the following stack trace:
E/MediaPlayerNative: error (1, -2147483648)
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.android.mediasession, PID: 11609
java.lang.RuntimeException: Failed to prepare stream:
at com.example.android.mediasession.service.players.MediaPlayerAdapter.playFile(MediaPlayerAdapter.java:130)
at com.example.android.mediasession.service.players.MediaPlayerAdapter.playFromMedia(MediaPlayerAdapter.java:87)
at com.example.android.mediasession.service.MusicService$MediaSessionCallback.onPlay(MusicService.java:145)
at android.support.v4.media.session.MediaSessionCompat$Callback$StubApi21.onPlay(MediaSessionCompat.java:1404)
at android.support.v4.media.session.MediaSessionCompatApi21$CallbackProxy.onPlay(MediaSessionCompatApi21.java:196)
at android.media.session.MediaSession$CallbackMessageHandler.handleMessage(MediaSession.java:1486)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: java.io.IOException: Prepare failed.: status=0x1
at android.media.MediaPlayer._prepare(Native Method)
at android.media.MediaPlayer.prepare(MediaPlayer.java:1282)
at com.example.android.mediasession.service.players.MediaPlayerAdapter.playFile(MediaPlayerAdapter.java:128)
at com.example.android.mediasession.service.players.MediaPlayerAdapter.playFromMedia(MediaPlayerAdapter.java:87)
at com.example.android.mediasession.service.MusicService$MediaSessionCallback.onPlay(MusicService.java:145)
at android.support.v4.media.session.MediaSessionCompat$Callback$StubApi21.onPlay(MediaSessionCompat.java:1404)
at android.support.v4.media.session.MediaSessionCompatApi21$CallbackProxy.onPlay(MediaSessionCompatApi21.java:196)
at android.media.session.MediaSession$CallbackMessageHandler.handleMessage(MediaSession.java:1486)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
I have researched other reports of the "Prepare failed.: status=0x1" error online, but there does not seem to be a consensus as to the cause.
I've tried making the code change to use a stream before migrating to AndroidX, and after. The result is the same, with the app failing as above when playing a stream, but only when using AndroidX.
UPDATE: Further debugging has shown that I don't need to perform a full migration to AndroidX to trigger this error. Simply updating the support libraries used by the code sample from v27.0.2 to v28.0.0 in build.gradle is sufficient to stop the stream being played. Streaming still works when they are upgraded only to v27.1.1. However I'll leave the Title of this question as is, because the most likely way in which a developer might trigger this issue is by migrating to AndroidX as recommended by Google.
I ultimately determined that the root cause was the fact that the audio stream I was trying to play was served only over HTTP, and from SDK 28 onwards you need to explicitly allow connections to be made over non HTTPS using a network security config, as detailed here:
Android MediaPlayer java.io.IOException: Prepare failed.: status=0x1
In my application, I am playing files from URL using MediaPlayer API.
It plays the remote file very well, the problem comes while handling errors,
1] When a file is not available on a remote URL (i.e. 404)
error message in IOExcpeiton reads, "Prepare failed.: status=0x1"
2] When the phone is not connected to internet exception message is same i.e.
"Prepare failed.: status=0x1"
How do we differentiate between 404 & no connectivity states for better handling of exceptions?
So far I have understood the IOException with the error message "Prepare failed.: status=0x1" appears only when a requested resource file or URL not available
For Error : Prepare failed.: status=0x1
Ref: 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/
Ref : Internet Connection Error
getting an UnknownHostException will mean that the application was
able to connect to the Internet
No it doesn't. It means the application was unable to resolve the host name. That could be because the host name doesn't exist, or because it was unable to connect to the Internet to resolve it.
When there is no Internet connection.
No specific exception. "There is no Internet connection" doesn't have a well-defined meaning. The condition resolves to one of the other failure modes below.
When the URL cannot be found.
If the host cannot be found, UnknownHostException. If the content part of the URL cannot be found, HTTP 404.
When the request timed out.
ConnectException with 'connection timed out' as the message, or SocketTimeoutException if it's a read timeout.
When the website is down.
ConnectException with 'connection refused' as the message.
When access is denied.
HTTP 403.
I'm using MediaPlayer library to stream some audio files from my server. The problem is when I want to play ogg audio file with media player in android version 4.2.2 and it's ok when I play it in android nougat. It gives me this error while preparing ogg audio file:
E/Tag: Prepare failed.: status=0x106
E/MediaPlayer: error (1, -2147483648)
E/MediaPlayer: Error (1,-2147483648)
E/MediaPlayer: stop called in state 0
Is there any alternative way to stream ogg format in all devices?
by the way there is no problem with playing mp3 files in all android versions I'v tested.
Thank you ...
First you should add <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
Then set data source, maybe:
mp = new MediaPlayer();
mp.setAudioStreamType(AudioManager.STREAM_RING); will help;
And of course prepare file before start:
mp.prepare();
mp.start();
I am currently trying to utilize the Xamarin CrossMediaManager but there seems to be a problem regarding reading source from the apps internal storage. The source i'm trying to access is : /data/user/0/com.pickle.solenya/files/video/180724-084223550.mp4 This is my app package, and the location is an internal one.
I have tried a with a android content provider and accessing the file from files:// and content:// but without success.
The file does exist, and i have tried with other files, the file is found but the MediaPlayer either returns E/MediaPlayer(12941): Error (-38,0) or throws java.io.IOException: setDataSourceFD failed.: status=0x80000000 | SecurityException
More details around the thrown exceptions:
Couldn't open content://com.pickle.jaguar/video/180724-084223550.mp4: java.io.IOException: setDataSourceFD failed.: status=0x80000000
07-24 14:21:47.367 D/MediaPlayer(10784): setDataSource IOException | SecurityException happend :
07-24 14:21:47.367 D/MediaPlayer(10784): java.io.IOException: setDataSourceFD failed.: status=0x80000000
Requesting the following permissions at app start:
android.permission.RECORD_AUDIO
android.permission.CAMERA
android.permission.INTERNET
android.permission.READ_EXTERNAL_STORAGE
android.permission.WRITE_EXTERNAL_STORAGE
android.permission.ACCESS_WIFI_STATE
android.permission.MEDIA_CONTENT_CONTROL
android.permission.WAKE_LOCK
I'm getting an odd error from MediaPlayer while playing a live stream. The code was working perfectly before I upgraded my Nexus 10 to 5.1 from 5.0.x.
I get the error: error (-2147483648, 0) in the onError handler and have to stop the video. If I put a breakpoint in the error handler, the video plays perfectly on the device, so I don't know why it throws the error nor what it means.
I've tried debugging the MediaPlayer sources, but for some reason the binary on the device does not match the sources I have for 5.1. Either way it seems the error is coming up from the Native code.
I am able to play other media sources with he same code, it seems only the media with no duration information causes the error.
Here is the only useful info I get out of the log:
03-21 23:02:22.365: W/MediaPlayer(26062): info/warning (801, 0)
03-21 23:02:22.401: D/MediaPlayer(26062): getMetadata
03-21 23:02:22.416: W/MediaPlayer(26062): Stream has no duration and is therefore not seekable.
03-21 23:02:22.416: E/MediaPlayer(26062): error (-2147483648, 0)
03-21 23:02:22.427: E/MediaPlayer(26062): Error (-2147483648,0)
03-21 23:02:22.443: D/VideoView(26062): Error: -2147483648,0
03-21 23:02:22.446: W/Tag(26062): Playback error in -2147483648 info: 0
03-21 23:02:22.492: W/MediaPlayer(26062): info/warning (3, 0)
Figured it out. I was calling seekTo() with a zero value on a stream with no duration (live stream). Why it worked before, the 5.1 upgrade, I don't know.