android - MediaPlayer setDataSource failed with status=0x80000000 for Ringtone set by filepath on 2.3.4 -
title says of it.
my application has been playing ringtones pointed uri content://media/internal/audio/media/387
or content://media/external/audio/media/1655
(for custom ringtones on sdcard believe) using both setdatasource(fileinfo)
, setdatasource(mcontext, uri.parse(fileinfo))
.
in each case have received logs information setdatasource failed.: status=0x80000000
exception on phones using android 4.x (different versions).
seeing error happens ringtones pointed content uri, not single files pointed path, have decided use paths ringtones fixed problem on above phones (while still using setdatasource(mcontext, uri.parse(fileinfo))
)
it has started problems on phones android 2.3.4-2.3.6 (not on mine 2.3.3 though):
- i have received few logs exception:
setdatasource failed.: status=0x80000000
files paths/system/media/audio/ringtones/twirlaway.ogg
i have received log
mediaplayer.onerrorlistener.onerror(int what, int extra)
method callwhat=1
,extra=-2147483648
, which, know, suggest either file missing or corrupted. performfile file = new file(fileinfo); if (!file.exists())
check in such situation , returned file exist - corrupted then? highly unlikely music file in internal memory.
to sum up:
- works
setdatasource("content://media/internal/audio/media/52")
- throws exception:
setdatasource failed.: status=0x80000000
setdatasource(mcontext, "/system/media/audio/ringtones/twirlaway.ogg")
interestingly, first few lines of setdatasource(context context, uri uri, headers headers)
method called setdatasource(context context, uri uri)
(from grepcode source 2.3.4):
string scheme = uri.getscheme(); if(scheme == null || scheme.equals("file")) { setdatasource(uri.getpath()); return; }
so, after all, fails setdatasource("/system/media/audio/ringtones/twirlaway.ogg")
. have taken paths ringtones uris 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 can causing error throwing? maybe issues caused lack of reading permissions? guess source code native setdatasource(string path) function lot, wasn't able find it.
answer lorne below helpful when dealing problem.
for else struggling it, here code have been using on 6 months errors not reported anymore.
fileinfo
can both of below (examples):
/system/media/audio/alarms/walk_in_the_forest.ogg
content://media/internal/audio/media/20
public static void setmediaplayerdatasource(context context, mediaplayer mp, string fileinfo) throws exception { if (fileinfo.startswith("content://")) { try { uri uri = uri.parse(fileinfo); fileinfo = getringtonepathfromcontenturi(context, uri); } catch (exception e) { } } try { if (android.os.build.version.sdk_int < android.os.build.version_codes.honeycomb) try { setmediaplayerdatasourceprehoneycomb(context, mp, fileinfo); } catch (exception e) { setmediaplayerdatasourceposthoneycomb(context, mp, fileinfo); } else setmediaplayerdatasourceposthoneycomb(context, mp, fileinfo); } catch (exception e) { try { setmediaplayerdatasourceusingfiledescriptor(context, mp, fileinfo); } catch (exception ee) { string uri = getringtoneurifrompath(context, fileinfo); mp.reset(); mp.setdatasource(uri); } } } private static void setmediaplayerdatasourceprehoneycomb(context context, mediaplayer mp, string fileinfo) throws exception { mp.reset(); mp.setdatasource(fileinfo); } private static void setmediaplayerdatasourceposthoneycomb(context context, mediaplayer mp, string fileinfo) throws exception { mp.reset(); mp.setdatasource(context, uri.parse(uri.encode(fileinfo))); } private static void setmediaplayerdatasourceusingfiledescriptor( context context, mediaplayer mp, string fileinfo) throws exception { file file = new file(fileinfo); fileinputstream inputstream = new fileinputstream(file); mp.reset(); mp.setdatasource(inputstream.getfd()); inputstream.close(); } private static string getringtoneurifrompath(context context, string path) { uri ringtonesuri = mediastore.audio.media.getcontenturiforpath(path); cursor ringtonecursor = context.getcontentresolver().query( ringtonesuri, null, mediastore.audio.media.data + "='" + path + "'", null, null); ringtonecursor.movetofirst(); long id = ringtonecursor.getlong(ringtonecursor .getcolumnindex(mediastore.audio.media._id)); ringtonecursor.close(); if (!ringtonesuri.tostring().endswith(string.valueof(id))) { return ringtonesuri + "/" + id; } return ringtonesuri.tostring(); } public 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(); string path = ringtonecursor.getstring(ringtonecursor .getcolumnindexorthrow(mediastore.audio.media.data)); ringtonecursor.close(); return path; }
Comments
Post a Comment