Skip to content

Commit

Permalink
fix(music bug): music disabled bug fixed, gameplay working correct
Browse files Browse the repository at this point in the history
  • Loading branch information
jcrucesdeveloper committed Mar 5, 2023
1 parent 8221eb9 commit 0347759
Showing 1 changed file with 19 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ public class PlayGameActivity extends AppCompatActivity {
private ArrayList<StationView> stationViews;

// Music
private MediaPlayer mediaPlayerMusicGameplay;
private MediaPlayer mediaPlayerGameplayGameplay;
private boolean isReproducingGameplayMusic = false;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand Down Expand Up @@ -96,15 +97,16 @@ private void drawStationView(float marginStart, String stationName, String color

private void reproduceMusic() {
if (MediaPlayerReproducer.getInstance().getMusicBoolean()) {
this.mediaPlayerMusicGameplay = MediaPlayer.create(this, R.raw.music_gameplay_loop);
this.mediaPlayerMusicGameplay.setLooping(true);
this.mediaPlayerMusicGameplay.start();
this.mediaPlayerGameplayGameplay = MediaPlayer.create(this, R.raw.music_gameplay_loop);
this.mediaPlayerGameplayGameplay.setLooping(true);
this.mediaPlayerGameplayGameplay.start();
isReproducingGameplayMusic = true;
}
}

private void stopMusic() {
if (this.mediaPlayerMusicGameplay != null) {
this.mediaPlayerMusicGameplay.stop();
if (this.mediaPlayerGameplayGameplay != null) {
this.mediaPlayerGameplayGameplay.stop();
}
}

Expand Down Expand Up @@ -302,7 +304,7 @@ private void onCorrectAlternative() {
}

public void onWinLevel() {
this.mediaPlayerMusicGameplay.stop();
this.stopMusicGameplay();
// Reproduce win sound
MediaPlayerReproducer.getInstance().reproduceSoundWinLevel(this);
this.updateProgressInfo();
Expand Down Expand Up @@ -356,9 +358,18 @@ private void onIncorrectAlternative() {
this.onLostLevel();
}

private void stopMusicGameplay() {
if(isReproducingGameplayMusic) {
if(mediaPlayerGameplayGameplay != null) {
this.mediaPlayerGameplayGameplay.stop();
isReproducingGameplayMusic = false;
}
}
}

private void onLostLevel() {
// Stop Gameplay Music
this.mediaPlayerMusicGameplay.stop();
this.stopMusicGameplay();
MediaPlayerReproducer.getInstance().reproduceLostSound(this);

// TODO - Ads
Expand Down

0 comments on commit 0347759

Please sign in to comment.