Uri with File:/// vs Content:// -- 检索音乐文件信息
我注意到我的代码的行为有些奇怪,希望有人能提供一些线索。
String temp = "file:///sdcard/music/05 Folsom Prison Blues.mp3";
String temp2 = "content://media/external/audio/media/10";
Uri uri = Uri.parse(temp);
Cursor musiccursor = null;
musiccursor = managedQuery(uri, null, null, null, null);
try {
if (musiccursor.moveToFirst()) {
String title;
int titleColumn = musiccursor.getColumnIndexOrThrow(MediaStore.Audio.Media.TITLE);
title = musiccursor.getString(titleColumn);
item.setText(title);
}
我注意到的问题是,使用 temp2 一切运行正常,我能够获得歌曲的标题。但是对于临时音乐光标每次都是空的,所以我们抛出一个空指针异常。知道这里有什么区别吗?我已经尝试过 temp 的编码版本(将空格转换为 %20 等),但这不起作用。我可以使用 temp2 创建的 uri 来使用意图来播放歌曲,没有问题...不知道我在这里缺少什么。
提前致谢!
I've noticed something odd about the behavior of my code and am hoping someone can shed some light.
String temp = "file:///sdcard/music/05 Folsom Prison Blues.mp3";
String temp2 = "content://media/external/audio/media/10";
Uri uri = Uri.parse(temp);
Cursor musiccursor = null;
musiccursor = managedQuery(uri, null, null, null, null);
try {
if (musiccursor.moveToFirst()) {
String title;
int titleColumn = musiccursor.getColumnIndexOrThrow(MediaStore.Audio.Media.TITLE);
title = musiccursor.getString(titleColumn);
item.setText(title);
}
The problem I'm noticing is that with temp2 everything runs fine, I'm able to get the song's title. But with temp musiccursor is null every time so we throw a nullpointerexception. Any idea what the difference is here? I've tried the encoded version of temp (converts spaces to %20 etc) and that doesn't work. I can use the uri that is created with temp2 to play the song using an intent no problem... Not sure what I'm missing here.
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
file://
不是由内容提供者管理的方案(只有content://
是),因此ContentResolver
不会能够用它做任何事情。file://
is not a scheme managed by a content provider (onlycontent://
is), and so aContentResolver
will not be able to do anything with it.