gpt4 book ai didi

android - 获取外部卡上的所有 MP3 文件

转载 作者:行者123 更新时间:2023-11-29 18:02:22 25 4
gpt4 key购买 nike

我想要实现的是在数组列表中获取所有 mp3 文件的 URL 和标题以返回它。全部来自文件夹:/ext_card/Music/和所有子文件夹。

我探索过的选项似乎都卡住了,我在互联网上查找的所有答案都指向 mediastore,但我不知道如何使用它

并且不要跟我说 RTFM 废话,因为我找到的关于 mediastore 的解释充其量是迟钝的。

那么谁能帮我解决问题,或者给我一个针对所有 mp3 文件的简单有效媒体存储查询示例?

最佳答案

使用它可以帮助您从 SD 卡中获取所有 MP3 歌曲

private static ArrayList<genericSongClass> songs = null;

public void BindAllSongs() {
/** Making custom drawable */
String selection = MediaStore.Audio.Media.IS_MUSIC + " != 0";
final String[] projection = new String[] {
MediaStore.Audio.Media.DISPLAY_NAME,
MediaStore.Audio.Media.ARTIST,
MediaStore.Audio.Media.DATA};
final String sortOrder = MediaStore.Audio.AudioColumns.TITLE
+ " COLLATE LOCALIZED ASC";

try {
// the uri of the table that we want to query
Uri uri = android.provider.MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
// query the db
cursor = getBaseContext().getContentResolver().query(uri,
projection, selection, null, sortOrder);
if (cursor != null) {
songs = new ArrayList<genericSongClass>(cursor.getCount());
cursor.moveToFirst();
while (!cursor.isAfterLast()) {
GSC = new genericSongClass();
GSC.songTitle = cursor.getString(0);
GSC.songArtist = cursor.getString(1);
GSC.songData = cursor.getString(2);
songs.add(GSC);
cursor.moveToNext();
}
}
} catch (Exception ex) {

} finally {
if (cursor != null) {
cursor.close();
}
}

}

public class genericSongClass {
String songTitle = "";
String songArtist = "";
String songData = "";
String isChecked = "false";
}

关于android - 获取外部卡上的所有 MP3 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15244282/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com