【发布时间】:2018-04-18 14:09:22
【问题描述】:
我正在使用 MediaStore 和 Cursor 从指定文件夹中获取音频文件。我想要的是,它应该从手机的内部存储中获取最新的歌曲列表,但它没有获取最新的文件。
例如:我正在录制音频,然后将其保存在特定文件夹中。但是当我在我的应用程序的播放列表中看到时。它不存在他们的。尽管该文件已成功保存在我的内部存储中。
我也调试过 cursor.getCount 也没有返回更新后的计数。
String AudioFilePath = "%" +"/nexcox/voicerecorder/audio/" +"%";
Uri uri= MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
String selection= MediaStore.Audio.Media.DATA +" LIKE ? ";
Cursor cursor=context.getContentResolver().query(uri,null,selection,
new String[]{AudioFilePath},
null);
if (cursor!=null){
if (cursor.moveToFirst()){
do {
String name = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.DISPLAY_NAME));
String duration = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.DURATION));
String sourceLocation = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.DATA));
AudioInfo audioInfo=new AudioInfo(name,duration,sourceLocation);
audioInfos.add(audioInfo);
}while (cursor.moveToNext());
}
cursor.close();
audioAdapter=new AudioAdapter(context,audioInfos);
recyclerView.setAdapter(audioAdapter);
}
【问题讨论】:
-
它目前在做什么?好吧,它没有做你想做的事,但它在做什么呢?例子 ?输出?
-
@xoxel 我已经编辑了描述。请看一下。
-
这显然不是我要的,示例?您是否尝试过通过打印名称、持续时间和 sourceLocation 进行调试?只是看看它是否正确?然后你有没有尝试在 cursor.close() 之后这样做?
-
录制完成后是否使用
MediaScannerConnection? -
@xoxel 看到光标计数返回 3,因为在该文件夹中存在大约 10 个文件。
标签: java android android-mediaplayer media-player mediastore