android - using mediaplayer class to play song present in external sd card but not working -


i have extracted mp3 files present in sd card , clicking upon particular song, calls class playsong , passes name of song in constructor via i'm trying play file using create method of mediaplayer file, not working @ me showing null pointer exception.

public class playsong {      mediaplayer mp;     context context;     string  title;     public playsong(context context,string title)     {         this.title=title;         this.context=context;     }      public void play_song()     {         //toast.maketext(context, "yes", 0).show();         string [] str=title.split("-");         string name=str[0];          //toast.maketext(context, ""+name, 0).show();         //mp = new mediaplayer();         try         {         mp = mediaplayer.create(context, uri.parse(environment.getexternalstoragedirectory().getpath()+ "/songs/"+name+".mp3"));         //mp.setaudiostreamtype(audiomanager.stream_music);         //mp.setlooping(true);         mp.start();         }         catch(exception ex)          {             toast.maketext(context, ""+ex, 0).show();          }     }  } 

nullpointer because uri.parse did not assigned path. try printing path -environment.getexternalstoragedirectory().getpath()+"/songs/"+name+".mp3" understanding is, should give path mounted sdcord index, , accessible path "sdcard/songs/"+name+".mp3"


Comments