Android 专辑封面
我正在开发一种 Android 媒体播放器,想要获得专辑封面,并使用此代码。
Uri sArtworkUri = Uri.parse("content://media/external/audio/albumart");
Uri uri = ContentUris.withAppendedId(sArtworkUri, album_id);
ContentResolver res = context.getContentResolver();
try {
in = res.openInputStream(uri);
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
Bitmap artwork = BitmapFactory.decodeStream(in);
但我得到 FileNotfoundExeption,并且艺术品设置为 null(
这是 LogCat
09-06 14:55:56.713: ERROR/MetadataRetrieverClient(34): failed to extract an album art
09-06 14:55:56.723: WARN/System.err(536): java.io.FileNotFoundException: No entry for content://media/external/audio/albumart/1
09-06 14:55:56.733: WARN/System.err(536): at android.database.DatabaseUtils.readExceptionWithFileNotFoundExceptionFromParcel(DatabaseUtils.java:123)
09-06 14:55:56.733: WARN/System.err(536): at android.content.ContentProviderProxy.openAssetFile(ContentProviderNative.java:538)
09-06 14:55:56.733: WARN/System.err(536): at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:484)
09-06 14:55:56.733: WARN/System.err(536): at android.content.ContentResolver.openInputStream(ContentResolver.java:319)
09-06 14:55:56.733: WARN/System.err(536): at player.org.Progress.onCreate(Progress.java:92)
09-06 14:55:56.733: WARN/System.err(536): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
09-06 14:55:56.733: WARN/System.err(536): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
09-06 14:55:56.733: WARN/System.err(536): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
09-06 14:55:56.743: WARN/System.err(536): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
09-06 14:55:56.743: WARN/System.err(536): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
09-06 14:55:56.743: WARN/System.err(536): at android.os.Handler.dispatchMessage(Handler.java:99)
09-06 14:55:56.743: WARN/System.err(536): at android.os.Looper.loop(Looper.java:123)
09-06 14:55:56.743: WARN/System.err(536): at android.app.ActivityThread.main(ActivityThread.java:3683)
09-06 14:55:56.743: WARN/System.err(536): at java.lang.reflect.Method.invokeNative(Native Method)
09-06 14:55:56.743: WARN/System.err(536): at java.lang.reflect.Method.invoke(Method.java:507)
09-06 14:55:56.743: WARN/System.err(536): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
09-06 14:55:56.743: WARN/System.err(536): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
09-06 14:55:56.753: WARN/System.err(536): at dalvik.system.NativeStart.main(Native Method)
I am developing a sort of media player for android, want to get Album Art, and use this code.
Uri sArtworkUri = Uri.parse("content://media/external/audio/albumart");
Uri uri = ContentUris.withAppendedId(sArtworkUri, album_id);
ContentResolver res = context.getContentResolver();
try {
in = res.openInputStream(uri);
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
Bitmap artwork = BitmapFactory.decodeStream(in);
But I get FileNotfoundExeption, and artwork sets to null(
Here is the LogCat
09-06 14:55:56.713: ERROR/MetadataRetrieverClient(34): failed to extract an album art
09-06 14:55:56.723: WARN/System.err(536): java.io.FileNotFoundException: No entry for content://media/external/audio/albumart/1
09-06 14:55:56.733: WARN/System.err(536): at android.database.DatabaseUtils.readExceptionWithFileNotFoundExceptionFromParcel(DatabaseUtils.java:123)
09-06 14:55:56.733: WARN/System.err(536): at android.content.ContentProviderProxy.openAssetFile(ContentProviderNative.java:538)
09-06 14:55:56.733: WARN/System.err(536): at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:484)
09-06 14:55:56.733: WARN/System.err(536): at android.content.ContentResolver.openInputStream(ContentResolver.java:319)
09-06 14:55:56.733: WARN/System.err(536): at player.org.Progress.onCreate(Progress.java:92)
09-06 14:55:56.733: WARN/System.err(536): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
09-06 14:55:56.733: WARN/System.err(536): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
09-06 14:55:56.733: WARN/System.err(536): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
09-06 14:55:56.743: WARN/System.err(536): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
09-06 14:55:56.743: WARN/System.err(536): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
09-06 14:55:56.743: WARN/System.err(536): at android.os.Handler.dispatchMessage(Handler.java:99)
09-06 14:55:56.743: WARN/System.err(536): at android.os.Looper.loop(Looper.java:123)
09-06 14:55:56.743: WARN/System.err(536): at android.app.ActivityThread.main(ActivityThread.java:3683)
09-06 14:55:56.743: WARN/System.err(536): at java.lang.reflect.Method.invokeNative(Native Method)
09-06 14:55:56.743: WARN/System.err(536): at java.lang.reflect.Method.invoke(Method.java:507)
09-06 14:55:56.743: WARN/System.err(536): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
09-06 14:55:56.743: WARN/System.err(536): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
09-06 14:55:56.753: WARN/System.err(536): at dalvik.system.NativeStart.main(Native Method)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论