I am making a music player. so in album section, I try to load an image of an album by the Picasso library. images are loaded correctly but when I scroll then app lagging problem occur. I also try with glide but no improvement in performance.I think that this problem occurs due to image load from this link " content://media/external/audio/albumart ". is there any alternative method if not then how to improve scrolling performance..??
public class Song_Adapter extends
RecyclerView.Adapter<Song_Adapter.MyViewHolder> implements
FastScrollRecyclerView.SectionedAdapter {
ArrayList<Song_base> song_info;
Context context;
LayoutInflater inflater;
LayoutInflater inflater1;
Home home;
AlertDialog.Builder dialog;
AlertDialog dg;
TextView remove,play,search,send,set_ringtone,detail;
DatabaseHelperAdapter helper;
public Song_Adapter(ArrayList<Song_base> song_info, Context context) {
this.song_info = song_info;
this.context = context;
inflater = LayoutInflater.from(context);
inflater1 = LayoutInflater.from(context);
}
@Override
public Song_Adapter.MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = inflater.inflate(R.layout.recycler_song_layout, parent, false);
return new Song_Adapter.MyViewHolder(v);
}
@Override
public void onBindViewHolder(final MyViewHolder holder, final int position)
{
final Song_base song = song_info.get(position);
holder.song_name.setText(song.getSong_name());
holder.artist.setText(song.getArtist());
holder.duration.setText(Constants.calculatetime(Integer.parseInt(
song.getDuration())));
getimageart(song.getAlbumId(), song.getContext(), holder.bannerp
}
@Override
public int getItemCount() {
return song_info.size();
}
public class MyViewHolder extends RecyclerView.ViewHolder {
TextView song_name, artist,duration;
CardView cardView;
Button play;
ImageView bannerp;
RelativeLayout relativeLayout;
public MyViewHolder(View itemView) {
super(itemView);
song_name = itemView.findViewById(R.id.song_name);
artist = itemView.findViewById(R.id.artist);
cardView = itemView.findViewById(R.id.cardview);
bannerp = itemView.findViewById(R.id.small_banner);
relativeLayout = itemView.findViewById(R.id.cardrelative);
duration = itemView.findViewById(R.id.duration);
}
}
public static void getimageart(Long albumId,Context context,ImageView image) {
Uri sArtworkUri = Uri.parse("content://media/external/audio/albumart");
Uri albumArtUri = ContentUris.withAppendedId(sArtworkUri, albumId);
Bitmap bitmapimage = null;
try {
bitmapimage = MediaStore.Images.Media.getBitmap(
context.getContentResolver(), albumArtUri);
}
catch (Exception exception) {
exception.printStackTrace();
}
if(bitmapimage!=null)
{
Picasso.with(context)
.load(Uri.parse(String.valueOf(albumArtUri)))
.resize(200,200)
.centerInside()
.into(image);
}
}
}