gpt4 book ai didi

android - 获取音乐播放器 Android 的专辑封面

转载 作者:太空宇宙 更新时间:2023-11-03 12:34:48 27 4
gpt4 key购买 nike

我想知道如何在音乐播放器中返回专辑封面图像的代码(功能)。你能解释一下我应该传递哪些参数吗?我可以将文件路径传递给函数。

imported required libraries

public class SongsManager {
// SDCard Path
final String MEDIA_PATH = new String("/sdcard/");
private ArrayList<HashMap<String, String>> songsList = new ArrayList<HashMap<String, String>>();

// Constructor
public SongsManager(){

}
public ArrayList<HashMap<String, String>> getPlayList(){
File home = new File(MEDIA_PATH);

if (home.listFiles(new FileExtensionFilter()).length > 0) {
for (File file : home.listFiles(new FileExtensionFilter())) {
HashMap<String, String> song = new HashMap<String, String>();
song.put("songTitle", file.getName().substring(0, (file.getName().length() - 4)));
song.put("songPath", file.getPath());
// Adding each song to SongList
songsList.add(song);
}
}
// return songs list array
return songsList;
}

class FileExtensionFilter implements FilenameFilter {
public boolean accept(File dir, String name) {
return (name.endsWith(".mp3") || name.endsWith(".MP3"));
}
}
}

最佳答案

尝试以下操作:

MediaMetadataRetriever mmr = new MediaMetadataRetriever();
mmr.setDataSource(file.getPath());
byte [] data = mmr.getEmbeddedPicture();
Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
imageView.setImageBitmap(bitmap);

关于android - 获取音乐播放器 Android 的专辑封面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23265502/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com