i want play song present in phone internal memory (i.e.no sd card) in music file of media file .
string filename = "1.mp3"; string completepath = environment.getexternalstoragepublicdirectory(environment.directory_music) + "/"+ filename; file file = new file(completepath); uri myuri1 = uri.fromfile(file); final mediaplayer mplayer = new mediaplayer(); mplayer.setaudiostreamtype(audiomanager.stream_music); try { mplayer.setdatasource(getapplicationcontext(), myuri1); } catch (illegalargumentexception e) { toast.maketext(getapplicationcontext(), "you might not set uri correctly!", toast.length_long).show(); } catch (securityexception e) { toast.maketext(getapplicationcontext(), "you might not set uri correctly!", toast.length_long).show(); } catch (illegalstateexception e) { toast.maketext(getapplicationcontext(), "you might not set uri correctly!", toast.length_long).show(); } catch (ioexception e) { e.printstacktrace(); } try { mplayer.prepare(); } catch (illegalstateexception e) { toast.maketext(getapplicationcontext(), "you might not set uri correctly!", toast.length_long).show(); } catch (ioexception e) { toast.maketext(getapplicationcontext(), "you might not set uri correctly!", toast.length_long).show(); } mplayer.start();
use code below file (audio) external storage, , play music,
string path = environment.getexternalstorage + "/"+ filename+".mp3"; mediaplayer player = new mediaplayer(); try { player.setdatasource(path); player.prepare(); } catch (illegalargumentexception e) { e.printstacktrace(); } catch (exception e) { system.out.println("exception of type : " + e.tostring()); e.printstacktrace(); } player.start();
do not forget put permision.
android.permission.read_external_storage
Comments
Post a Comment