Android 怎么读取指定目录下的音乐文件
2个回答
展开全部
ContentResolver mResolver = getContentResolver();
Cursor cursor = mResolver.query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, null, null, null, MediaStore.Audio.Media.DEFAULT_SORT_ORDER);
int i = 0;
int cursorCount = cursor.getCount();
if (cursorCount >0 )
{
cursor.moveToFirst();
while (i < cursorCount)
{
//歌曲文件的路径 :MediaStore.Audio.Media.DATA
url = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.DATA));
if(url.toLowerCase().indexOf("指定的歌曲路径") > 0)
{
......
}
i++;
cursor.moveToNext();
}
cursor.close();
}
Cursor cursor = mResolver.query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, null, null, null, MediaStore.Audio.Media.DEFAULT_SORT_ORDER);
int i = 0;
int cursorCount = cursor.getCount();
if (cursorCount >0 )
{
cursor.moveToFirst();
while (i < cursorCount)
{
//歌曲文件的路径 :MediaStore.Audio.Media.DATA
url = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.DATA));
if(url.toLowerCase().indexOf("指定的歌曲路径") > 0)
{
......
}
i++;
cursor.moveToNext();
}
cursor.close();
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2018-04-18
引用书飞凝683的回答:
ContentResolver mResolver = getContentResolver();
Cursor cursor = mResolver.query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, null, null, null, MediaStore.Audio.Media.DEFAULT_SORT_ORDER);
int i = 0;
int cursorCount = cursor.getCount();
if (cursorCount >0 )
{
cursor.moveToFirst();
while (i < cursorCount)
{
//歌曲文件的路径 :MediaStore.Audio.Media.DATA
url = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.DATA));
if(url.toLowerCase().indexOf("指定的歌曲路径") > 0)
{
......
}
i++;
cursor.moveToNext();
}
cursor.close();
}
ContentResolver mResolver = getContentResolver();
Cursor cursor = mResolver.query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, null, null, null, MediaStore.Audio.Media.DEFAULT_SORT_ORDER);
int i = 0;
int cursorCount = cursor.getCount();
if (cursorCount >0 )
{
cursor.moveToFirst();
while (i < cursorCount)
{
//歌曲文件的路径 :MediaStore.Audio.Media.DATA
url = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.DATA));
if(url.toLowerCase().indexOf("指定的歌曲路径") > 0)
{
......
}
i++;
cursor.moveToNext();
}
cursor.close();
}
展开全部
在检索的时候就能解决为什么这么麻烦
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询