0
我已經看到此MediaPlayer tutorial,而且如果有人幫我設置音頻文件,則直接從Raw
文件夾播放而不是/SdCard/
?從原始文件夾中獲取音頻文件而不是SdCard
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 to read all mp3 files from sdcard and store the details in
* ArrayList
* */
public ArrayList<HashMap<String, String>> getPlayList() {
File home = new File(MEDIA_PATH);
if (home.listFiles(new FileExtensionFilter()).length > 0) {
for (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 to SongList
songsList.add(song);
}
}
// return songs list array
return songsList;
}
/**
* Class to filter files which are having .mp3 extension
* */
class FileExtensionFilter implements FilenameFilter {
public boolean accept(File dir, String name) {
return (name.endsWith(".mp3") || name.endsWith(".MP3"));
}
}
}
謝謝兄弟(Jibran汗),但你可以告訴我,我怎樣才能把它添加到當前SongsManager.java文件? – scholar 2013-05-02 06:54:29
請查看我的編輯,瞭解如何從原始文件夾將媒體播放器設置爲媒體播放器。 – 2013-05-02 06:59:00
不是視頻文件,但它們是音頻。 final String MEDIA_PATH = new String(「/ sdcard /」); File home = new File(MEDIA_PATH); – scholar 2013-05-02 07:05:43