我知道这个问题被问了很多次,但我在下面的这段代码中有轻微的混淆
public class AudioAdapter extends RecyclerView.Adapter<AudioAdapter.AudioViewHolder> {
private List<MusicFiles> audioList;
private Context context;
public AudioAdapter(List<MusicFiles> audioList, Context context) {
this.audioList = audioList;
this.context = context;
}
@NonNull
@NotNull
@Override
public AudioViewHolder onCreateViewHolder(@NonNull @NotNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(context).inflate(R.layout.custom_audio_item_layout, parent, false);
return new AudioViewHolder(view);
}
@Override
public void onBindViewHolder(@NonNull @NotNull AudioAdapter.AudioViewHolder holder, int position) {
holder.audioName.setText(audioList.get(position).getTitle());
Log.d("dslafjk__", "imagePath :" + audioList.get(position).getPath());
//Above Log return this path
//imagePath :/storage/emulated/0/snaptube/download/SnapTube Audio/Angrej _ Full Songs Audio Jukebox _ Amrinder Gill(MP3_160K).mp3
byte[] image = getAlbumImage(audioList.get(0).getPath());
if (image != null) {
Glide.with(context).asBitmap()
.load(image)
.into(holder.audioImage);
} else {
Glide.with(context)
.load(R.drawable.music_image_placeholder)
.into(holder.audioImage);
}
}
@Override
public int getItemCount() {
return audioList.size();
}
public class AudioViewHolder extends RecyclerView.ViewHolder {
ImageView audioImage;
TextView audioName;
public AudioViewHolder(@NonNull @NotNull View itemView) {
super(itemView);
audioImage = itemView.findViewById(R.id.audioImage);
audioName = itemView.findViewById(R.id.audioName);
}
}
private byte[] getAlbumImage(String path) {
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
retriever.setDataSource(path);
byte[] audioImage = retriever.getEmbeddedPicture();
retriever.release();
return audioImage;
}
}
retriever.setDataSource(path)正在生成错误我有 google 和 stack 很多次,但我找不到解决方案。我也检查了这些链接