Title says most of it.
My application has been playing ringtones pointed by uri like content://media/internal/audio/media/387
or content://media/external/audio/media/1655
(for custom ringtones on SDcard I believe) using both setDataSource(fileInfo)
and setDataSource(mContext, Uri.parse(fileInfo))
.
In each case I have received logs with information about setDataSource failed.: status=0x80000000
exception on phones using Android 4.x (different versions).
Seeing that the error happens only to ringtones pointed by content uri, but not to single files pointed by path, I have decided to use paths for ringtones as well which fixed problem on above phones (while still using setDataSource(mContext, Uri.parse(fileInfo))
)
It has however started problems on phones with Android 2.3.4-2.3.6 (not on mine 2.3.3 though):
- I have received few logs with exception:
setDataSource failed.: status=0x80000000
for files with paths like /system/media/audio/ringtones/TwirlAway.ogg
I have also received a log about MediaPlayer.onErrorListener.onError(int what, int extra)
method call with what=1
and extra=-2147483648
, which, from what I know, suggest either that file is missing or it is corrupted. However I perform
File file = new File(fileInfo);
if (!file.exists())
check in such situation and it returned that file does exist - is it corrupted then? Highly unlikely for music file in internal memory.
To sum up:
- works with
setDataSource("content://media/internal/audio/media/52")
- throws exception:
setDataSource failed.: status=0x80000000
for setDataSource(mContext, "/system/media/audio/ringtones/TwirlAway.ogg")
Interestingly, first few lines of setDataSource(Context context, Uri uri, Headers headers)
method which is called by setDataSource(Context context, Uri uri)
are (from GrepCode source for 2.3.4):
String scheme = uri.getScheme();
if(scheme == null || scheme.equals("file")) {
setDataSource(uri.getPath());
return;
}
So, after all, it just fails for setDataSource("/system/media/audio/ringtones/TwirlAway.ogg")
. I have taken paths to ringtones from uris by using:
private static String getRingtonePathFromContentUri(Context context,
Uri contentUri) {
String[] proj = { MediaStore.Audio.Media.DATA };
Cursor ringtoneCursor = context.getContentResolver().query(contentUri,
proj, null, null, null);
ringtoneCursor.moveToFirst();
return ringtoneCursor.getString(ringtoneCursor
.getColumnIndexOrThrow(MediaStore.Audio.Media.DATA));
}
Any ideas what can be causing error throwing? Maybe those are some issues caused by lack of reading permissions?
I guess source code for native setDataSource(String path) function would help a lot, but I wasn't able to find it.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…