Android RingtoneManager media path for custom ringtones not playing anymore -


i upgraded old nexus device latest , mediaplayer wont play custom ringtone paths im retrieving way of ringtonemanager picker.

i have 2 media's example:

  1. content://media/internal/audio/media/86 --this 1 not play, custom ringtone ( mp3 downloaded , added /media/audio/ringtones/)

and

  1. content://media/internal/audio/media/54 --this 1 plays

im trying play both mediaplayer api in android. both media paths returned me ringtonemanager follows:

intent intent = new intent(ringtonemanager.action_ringtone_picker);          // activity stack history, 1 time deal     //  intent.setflags(intent.flag_activity_no_history);         intent.putextra(ringtonemanager.extra_ringtone_title,                 "please select  ringtone");           intent.putextra(ringtonemanager.extra_ringtone_type, ringtonemanager.type_all);         intent.putextra(ringtonemanager.extra_ringtone_show_default, true);         //intent.putextra(ringtonemanager.extra_ringtone_include_drm, true);           try {// 44 arbitrary number recognize our intent             startactivityforresult(intent, 44); } //etc 

and here how retrieve selected ringtone. works except when user picks custom ringtone list, mediaplayer io exception data resource cannot played.

// find out ringtone user selected , play tone. protected  void onactivityresult(int requestcode, int resultcode, intent data) {     ringtone ringtone;      if (requestcode == 44 && resultcode == result_ok) {         uri uri = data.getparcelableextra(ringtonemanager.extra_ringtone_picked_uri); 

}

//the uri retrieved , value is: content://media/internal/audio/media/86

here mediaplayer error receive when try ti play custom ringtone :

  e = {java.io.ioexception@4499} "java.io.ioexception: setdatasource failed.: status=0x80000000"  cause = {java.io.ioexception@4499} "java.io.ioexception: setdatasource failed.: status=0x80000000"  detailmessage = {java.lang.string@4503} "setdatasource failed.: status=0x80000000" 

any other media works fine not custom ringtones.

looks path not accepted , have use full path custom ringtone reason. google, there reason why ? here workaround. check if uri valid isvaliduri. if not valid call getringtonepathfromcontenturi directory path resource , use instead. issue reported here

 /** * checks if url such content://media/internal/audio/media/86 can played.  * if not returns no , can fall else. **/     public boolean isvaliduri(string contenturi){          boolean result=true;          mediaplayer player = new mediaplayer();         try {             player.setdatasource(contenturi);         } catch (ioexception e) {             e.printstacktrace();             result = false;         }          return result;     }      //gets sd card path ringtone uri     public  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

Popular posts from this blog

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

php - Zend Framework / Skeleton-Application / Composer install issue -