Android 专辑封面

发布于 2024-12-03 09:31:45 字数 2881 浏览 1 评论 0原文

我正在开发一种 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文