3. Import Glide dependency to build.gradle (Module: app)
//Glide implementation 'com.github.bumptech.glide:glide:4.11.0' annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0'
holder.itemView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent intent = new Intent(mContext, PlayerActivity.class); intent.putExtra("sender", "albumDetails"); intent.putExtra("position", position); mContext.startActivity(intent); } });String sender = getIntent().getStringExtra("sender"); if (sender != null && sender.equals("albumDetails")) { listSongs = albumFiles; } else { listSongs = mFiles; }
ImageView's scaleType
5. Add FloatingActionButton in activity_player.xml
<com.google.android.material.floatingactionbutton.FloatingActionButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/play_pause" android:src="@drawable/ic_play" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:focusable="true" android:clickable="true"/>
//the animation of songs_changing public void ImageAnimation(final Context context, final ImageView imageView, final Bitmap bitmap) { Animation animOut = AnimationUtils.loadAnimation(context, android.R.anim.fade_out); final Animation animIn = AnimationUtils.loadAnimation(context, android.R.anim.fade_in); animOut.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { } @Override public void onAnimationEnd(Animation animation) { Glide.with(context).load(bitmap).into(imageView); animIn.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { } @Override public void onAnimationEnd(Animation animation) { } @Override public void onAnimationRepeat(Animation animation) { } }); imageView.startAnimation(animIn); } @Override public void onAnimationRepeat(Animation animation) { } }); imageView.startAnimation(animOut); }public class PlayerActivity extends AppCompatActivity implements MediaPlayer.OnCompletionListener{@Override public void onCompletion(MediaPlayer mp) { nextBtnClicked(); if (mediaPlayer != null) { mediaPlayer = MediaPlayer.create(getApplicationContext(), uri); mediaPlayer.start(); mediaPlayer.setOnCompletionListener(this); } }
<com.google.android.material.tabs.TabLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@color/colorPrimaryDark" android:id="@+id/tab_layout" app:tabIndicatorFullWidth="true" app:tabIndicatorGravity="center" app:tabTextColor="@color/colorAccent" app:tabIndicatorHeight="40dp" app:tabIndicatorColor="#009688" app:tabIndicator="@drawable/tab_indicator"/>2. ViewPager
<com.google.android.material.tabs.TabLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@color/colorPrimaryDark" android:id="@+id/tab_layout" app:tabIndicatorFullWidth="true" app:tabIndicatorGravity="center" app:tabTextColor="@color/colorAccent" app:tabIndicatorHeight="40dp" app:tabIndicatorColor="#009688" app:tabIndicator="@drawable/tab_indicator"/>public static class ViewPagerAdapter extends FragmentPagerAdapter { private ArrayList<Fragment> fragments; private ArrayList<String> titles; public ViewPagerAdapter(@NonNull FragmentManager fm) { super(fm); this.fragments = new ArrayList<>(); this.titles = new ArrayList<>(); } void addFragments(Fragment fragment, String title){ fragments.add(fragment); titles.add(title); } @NonNull @Override public Fragment getItem(int position) { return fragments.get(position); } @Override public int getCount() { return fragments.size(); } @Nullable @Override public CharSequence getPageTitle(int position) { return titles.get(position); } }
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"> <gradient android:centerColor="@color/colorPrimaryDark" android:angle="0"/> </shape>
holder.itemView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent intent = new Intent(mContext, AlbumDetails.class); intent.putExtra("albumName", albumFiles.get(position).getAlbum()); mContext.startActivity(intent); } });
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_album_details); recyclerView = findViewById(R.id.recyclerView); albumPhoto = findViewById(R.id.albumPhoto); albumName = getIntent().getStringExtra("albumName"); int j = 0; for (int i = 0 ; i < musicFiles.size() ; i ++) { if (albumName.equals(musicFiles.get(i).getAlbum())) { albumSongs.add(j, musicFiles.get(i)); j ++; } } byte[] image = getAlbumArt(albumSongs.get(0).getPath()); if (image != null) { Glide.with(this) .load(image) .into(albumPhoto); } else { Glide.with(this) .load(R.drawable.bewedoc) .into(albumPhoto); } }
@Override protected void onResume() { super.onResume(); if (!(albumSongs.size() < 1)) { albumDetailsAdapter = new AlbumDetailsAdapter(this, albumSongs); recyclerView.setAdapter(albumDetailsAdapter); recyclerView.setLayoutManager(new LinearLayoutManager(this, RecyclerView.VERTICAL, false)); } }