android - Play Song continously -
i working on music application , have recorded audio files, can play song individually have button play on need play song present in particular folder
can suggest best way achieve task
thanks in advance
hello guys got answer question finally
please check below code:
public class showallrecords extends listactivity { private file file; private list<string> mylist; mediaplayer mp; listview listv; int currentposition = 0; public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); mp = new mediaplayer(); mylist = new arraylist<string>(); listv = getlistview(); listv.setbackgroundresource(r.drawable.musicapp); string root_sd = environment.getexternalstoragedirectory().tostring(); file = new file(root_sd + "/mymusicapp/"); file list[] = file.listfiles(); (int j = 0; j < list.length; j++) { mylist.add(list[j].getname()); } listv.setadapter(new arrayadapter<string>(this, android.r.layout.simple_list_item_1, mylist)); } protected void onlistitemclick(listview l, view v, int position, long id) { super.onlistitemclick(l, v, position, id); file temp_file = new file(file, mylist.get(position)); if (!temp_file.isfile()) { file = new file(file, mylist.get(position)); file list[] = file.listfiles(); mylist.clear(); (int = 0; < list.length; i++) { mylist.add(list[i].getname()); } toast.maketext(getapplicationcontext(), file.tostring(), toast.length_long).show(); //+l.getadapter().getitem(position)); listv.setadapter(new arrayadapter<string>(this, android.r.layout.simple_list_item_1, mylist)); playsong(file.tostring() + "/" + mylist.get(currentposition)); l.setonitemclicklistener(new adapterview.onitemclicklistener() { @override public void onitemclick(adapterview<?> parent, view view, int position, long id) { system.out.println("path :--" + file.tostring() + "/" + mylist.get(position)); } }); // } } private void playsong(string songpath) { try { mp.reset(); mp.setdatasource(songpath); mp.prepare(); // mp.setlooping(true); mp.start(); mp.setoncompletionlistener(new mediaplayer.oncompletionlistener() { @override public void oncompletion(mediaplayer mediaplayer) { toast.maketext(getapplicationcontext(), "media completed success", toast.length_short).show(); system.out.println("in oncompletion"); try { currentposition++; // mediaplayer.reset(); if (currentposition <=mylist.size()) { system.out.println("in if of postion"); mediaplayer = new mediaplayer(); mediaplayer.reset(); mediaplayer.setdatasource(file.tostring() + "/"+mylist.get(currentposition)); system.out.println("file path on completion :--"+file.tostring() + mylist.get(currentposition)); mediaplayer.prepare(); // mp.setlooping(true); mediaplayer.start(); } // playsong(file.tostring() + mylist.get(currentposition)); system.out.println("path :--" + file.tostring() + currentposition); // nextsong(); } catch (exception e) { e.printstacktrace(); } } }); } catch (ioexception e) { log.v(getstring(r.string.app_name), e.getmessage()); } } }
Comments
Post a Comment