【问题标题】:displaying album art for music using picasso使用毕加索显示音乐的专辑封面
【发布时间】:2017-03-06 10:32:07
【问题描述】:

您好,我需要使用 Picasso 有效地显示音乐文件的专辑封面。我已经在我的应用程序中配置了毕加索。但我无法显示来自内部存储音乐文件的专辑封面。

我试过这段代码,但它不起作用意味着没有错误,但它不显示任何内容。

  1. 使用 uri :

    cursor = getContentResolver().query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, null, MediaStore.Audio.AudioColumns.DURATION + ">0", null, sortOrder);
    
    cursor.moveToFirst();
    
    a = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.ALBUM_ID));
    
    l = Long.parseLong(a);
    final Uri sArtworkUri = Uri.parse("content://media/external/audio/albumart");
    Uri uri = ContentUris.withAppendedId(sArtworkUri, l);
    
    Picasso.with(MainActivity.this).load(uri).into(iv);
    
  2. 使用新文件:

    cursor = getContentResolver().query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, null, MediaStore.Audio.AudioColumns.DURATION + ">0", null, sortOrder);
    
    cursor.moveToFirst();
    
    a = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.ALBUM_ID));
    
    Picasso.with(this)
           .load(Uri.parse("file://"+a))
           .error(R.drawable.color_music_player_logo)
           .into(iv);
    

【问题讨论】:

  • 给我们你的日志
  • 没有任何错误,只是不显示任何内容。
  • 如果您向清单添加了权限,我认为您这样做了。也许没有什么可显示的!尝试将图片放入您的资源中。 int resourceId = R.mipmap.ic_launcher.Picasso .with(context) .load(resourceId) .into(imageViewResource);
  • 这是正确的,但我想从 sd 卡或内部存储中获取图像,而不是从资源中获取。
  • 我的猜测是您尝试从中加载图像的地址或查询没有您想要的内容

标签: android uri picasso android-file


【解决方案1】:

像这样为您的图像提供 Picasso 的绝对路径:

String name = "image.jpeg";
String dir = Environment.getExternalStorageDirectory().getAbsolutePath();
Picasso.with(context).load(new File(dir + File.separator + name)).into(iv);

或者您可以使用filechooser,这样您就可以选择要加载的图像或显示图像列表,然后单击为您加载图像....

【讨论】:

  • 我会在下课后回复你,谢谢你的帮助
  • 好的好的,我会回复你的
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-01-12
  • 1970-01-01
  • 2021-06-21
  • 2017-01-05
  • 1970-01-01
相关资源
最近更新 更多