如何从内部和外部的SD卡在android的播放mp3文件? [英] How to play mp3 files from internal and external SD card in android?
本文介绍了如何从内部和外部的SD卡在android的播放mp3文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我工作的一个MP3播放器应用程序,这在任何地方发挥了内部SD卡里面的.mp3文件present。
I am working on a mp3 player app, which plays .mp3 files present anywhere inside an internal SD card.
我使用了下列codeS来获取.mp3文件present的内部存储。
I have used the following codes to fetch the .mp3 files present in internal storage.
ArrayList<File> inFiles = new ArrayList<File>();
File list[] = file.listFiles();
//Log.i("DIR", "PATH" +file.getPath());
for (int i = 0; i < list.length; i++)
{
// myList.add( list[i].getName() );
File temp_file = new File(file.getAbsolutePath(),list[i].getName());
//Log.i("DIR", "PATH" +temp_file.getAbsolutePath());
if (temp_file.listFiles() != null)
{
//Log.i("inside", "call fn");
listfiles(temp_file);
}
else
{
if (list[i].getName().toLowerCase().contains(".mp3"))
{
inFiles.add(list[i]);
//Log.e("Music", list[i].getName());
}
}
}
我如何同样得到外部SD卡中的.mp3文件中呢?
How do I similarly get the .mp3 files from external SD card as well?
推荐答案
尝试使用这样的:
File root = Environment.getExternalStorageDirectory();
这将让你的外部存储的根,只要有一个。然后你就可以过滤掉不.mp3文件
That will get you the root of the external storage, provided that there is one. Then you can filter out files that aren't .mp3
另外还要考虑看这个:全部列出一个文件的在Android设备类型?
Also consider looking at this: List all of one file type on Android device?
这篇关于如何从内部和外部的SD卡在android的播放mp3文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文