java - Android App/ to paly audio/videos files from Raw or Assets folder instead of /SDCard/ -
please me getting android app play audio /video files raw or assets folders instead playing /sdcard/.
what should change in code below ?
here tutorial code.
regards.
import java.io.file; import java.io.filenamefilter; import java.util.arraylist; import java.util.hashmap; public class songsmanager { // sdcard path @suppresslint("sdcardpath") final string media_path = new string("/sdcard/"); private arraylist<hashmap<string, string>> songslist = new arraylist<hashmap<string, string>>(); // constructor public songsmanager() { } /** * function read mp3 files sdcard , store details in * arraylist * */ public arraylist<hashmap<string, string>> getplaylist() { file home = new file(media_path); if (home.listfiles(new fileextensionfilter()).length > 0) { (file file : home.listfiles(new fileextensionfilter())) { hashmap<string, string> song = new hashmap<string, string>(); song.put( "songtitle", file.getname().substring(0, (file.getname().length() - 4))); song.put("songpath", file.getpath()); // adding each song songlist songslist.add(song); } } // return songs list array return songslist; } /** * class filter files having .mp3 extension * */ class fileextensionfilter implements filenamefilter { public boolean accept(file dir, string name) { return (name.endswith(".mp3") || name.endswith(".mp3")); } } }
u can try loading files assets folder..
consider there ringtone folder inside assets folder use in activity
assetmanager assetmanager = this.getresources().getassets(); string[] files = null; try { files = assetmanager.list("ringtone"); //ringtone folder name } catch (exception e) { log.e(log_tag, "error: " + e.tostring()); }
so u files assets folder next file name , pass files names list
Comments
Post a Comment