gpt4 book ai didi

Android 音乐文件的位置?

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:26:21 25 4
gpt4 key购买 nike

我正在编写一个音乐播放器应用程序,我想知道我应该在哪里查找用户的音乐文件。我想找到音乐应用程序通常能找到的所有歌曲,我很好奇该应用程序如何找到这些歌曲。是否有特定文件夹的枚举变量?只是递归搜索 sd 卡?我知道我手机的 SD 卡上有一个 Music 文件夹;在每台 Android 设备上都是这样吗?我应该只递归搜索该文件夹吗?还是我应该让用户找到文件夹?

最佳答案

您可以使用以下功能从 sdcard 中找到所有音乐文件。

public void getAllSongsFromSDCARD() 
{
String[] STAR = { "*" };
Uri allsongsuri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
String selection = MediaStore.Audio.Media.IS_MUSIC + " != 0";

cursor = managedQuery(allsongsuri, STAR, selection, null, null);

if (cursor != null) {
if (cursor.moveToFirst()) {
do {
String song_name = cursor
.getString(cursor
.getColumnIndex(MediaStore.Audio.Media.DISPLAY_NAME));
int song_id = cursor.getInt(cursor
.getColumnIndex(MediaStore.Audio.Media._ID));

String fullpath = cursor.getString(cursor
.getColumnIndex(MediaStore.Audio.Media.DATA));


String album_name = cursor.getString(cursor
.getColumnIndex(MediaStore.Audio.Media.ALBUM));
int album_id = cursor.getInt(cursor
.getColumnIndex(MediaStore.Audio.Media.ALBUM_ID));

String artist_name = cursor.getString(cursor
.getColumnIndex(MediaStore.Audio.Media.ARTIST));
int artist_id = cursor.getInt(cursor
.getColumnIndex(MediaStore.Audio.Media.ARTIST_ID));



} while (cursor.moveToNext());

}
cursor.close();
}
}

关于Android 音乐文件的位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5428507/

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