2

After finishing the tutorials (https://code.tutsplus.com/tutorials/create-a-music-player-on-android-user-controls--mobile-22787) on how to create a basic music player Android app as well as addressing most of the bugs there ranging from properly granting permissions to controller bugs, I noticed another bug where the controller doesn't update when paused after getting a phone call. I basically instantiate a PhoneStateListener to pause the song via a Service class that implements MediaPlayer interfaces as follows:

PhoneStateListener initialization in MainActivity:

private PhoneStateListener mPhoneStateListener = new PhoneStateListener() {
    @Override
    public void onCallStateChanged(int state, String incomingNumber) {
        switch (state) {
            case TelephonyManager.CALL_STATE_RINGING:

                // Pauses the song and hides the controller, respectively.
                mMusicService.pausePlayer();
                mController.hide();
                break;
        }
    }
};

Pause player method in the Service class:

public void pausePlayer(){
    mPlayer.pause();
}

Repo link: https://github.com/DaveNOTDavid/music-player-lite/tree/master/app/src/main/java/com/davenotdavid/musicplayerlite

... everything about the controller updates properly (duration, song length, and etc.) and the song pauses accordingly when answering the phone call, but the pause icon (instead of play) is still shown when returning back to the app.

DaveNOTDavid
  • 1,753
  • 5
  • 19
  • 37

0 Answers0