Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Hi Please Help... When we press the next song button, the screen turns white, and takes me to the previous screen . When we press
Hi Please Help... When we press the next song button, the screen turns white, and takes me to the previous screen When we press the previous song button, it makes us quit the app. This is our MusicActivity.java file in android studio
import android.content.Intent;
import android.media.MediaPlayer;
import android.osBundle;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ImageButton;
import android.widget.ImageView;
import androidx.activity.ComponentActivity;
public class MusicActivity extends ComponentActivity
ImageView img;
ImageView skipButton;
ImageView backButton;
boolean isPlaying false;
MediaPlayer musicPlayer;
private int currentSongIndex ;
int songCovers Rdrawable.md Rdrawable.whatevershewants, Rdrawable.snooze;
int songResources Rraw.million, Rraw.whatever, Rraw.snooze;
@Override
protected void onCreateBundle savedInstanceState
super.onCreatesavedInstanceState;
setContentViewRlayout.musicplayer;
setupButtons;
img findViewByIdRidplaypause;
skipButton findViewByIdRidskip;
backButton findViewByIdRidgoback;
musicPlayer MediaPlayer.createthis Rraw.million;
img.setOnClickListenernew View.OnClickListener
@Override
public void onClickView v
togglePlayPause;
;
skipButton.setOnClickListenernew View.OnClickListener
@Override
public void onClickView v
playNextSong;
;
backButton.setOnClickListenernew View.OnClickListener
@Override
public void onClickView v
playPreviousSong;
;
private void togglePlayPause
if isPlaying
musicPlayer.pause;
isPlaying false;
else
musicPlayer.start;
isPlaying true;
private void playNextSong
currentSongIndex currentSongIndex songCovers.length;
musicPlayer.stop;
musicPlayer MediaPlayer.createthis getSongResourcecurrentSongIndex;
musicPlayer MediaPlayer.createthis Rraw.whatever;
musicPlayer.start;
updateSongCover;
isPlaying true;
private void updateSongCover
int currentIndex getCurrentSongIndex;
img.setImageResourcesongCoverscurrentIndex;
private int getCurrentSongIndex
return currentSongIndex;
private void playPreviousSong
currentSongIndex currentSongIndex songCovers.length songCovers.length;
musicPlayer.stop;
musicPlayer MediaPlayer.createthis getSongResourcecurrentSongIndex;
musicPlayer.start;
updateSongCover;
isPlaying true;
private int getSongResourceint index
return songResourcesindex;
@Override
protected void onDestroy
super.onDestroy;
if musicPlayer null
musicPlayer.release;
musicPlayer null;
private void setupButtons
ImageButton buttonImageButton findViewByIdRidmusichome;
ImageButton buttonImageButton findViewByIdRidplaylist;
buttonsetOnClickListenernew View.OnClickListener
public void onClickView v
Intent intent new IntentMusicActivitythis, HomeActivity.class;
startActivityintent;
;
buttonsetOnClickListenernew View.OnClickListener
public void onClickView v
Intent intent new IntentMusicActivitythis, PlaylistManagement.class;
startActivityintent;
;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started