oppia-android icon indicating copy to clipboard operation
oppia-android copied to clipboard

[BUG]: App crashes when playing audio after Wi-Fi is turned off

Open subhajitxyz opened this issue 3 months ago • 3 comments

Describe the bug

Initially, audio playback works fine with Wi-Fi enabled. However, once Wi-Fi is disabled and the user tries to continue playback on the next card, the app crashes.

Steps To Reproduce

  • Play audio with Wi-Fi turned on.
  • Turn off Wi-Fi and move to the next card.
  • Observe that the loading spinner appears for a while and then stops.
  • Tap the play button again → the app crashes.

Expected Behavior

Instead of crashing, the app should display the same popup message shown for the offline state and close the audio bar fragment.

Screenshots/Videos

https://github.com/user-attachments/assets/5dbfbe38-af92-4ea1-8006-777f723bc4a2

Stacktrace

FATAL EXCEPTION: main
        Process: org.oppia.android, PID: 21633
        java.lang.IllegalStateException: Media Player not in a prepared state
        	at org.oppia.android.domain.audio.AudioPlayerController.play(AudioPlayerController.kt:168)
        	at org.oppia.android.app.player.audio.AudioViewModel.togglePlayPause(AudioViewModel.kt:145)
        	at org.oppia.android.app.databinding.databinding.AudioFragmentBindingImpl._internalCallbackOnClick(AudioFragmentBindingImpl.java:471)
        	at org.oppia.android.app.databinding.generated.callback.OnClickListener.onClick(OnClickListener.java:11)
        	at android.view.View.performClick(View.java:7575)
        	at android.view.View.performClickInternal(View.java:7531)
        	at android.view.View.access$3900(View.java:842)
        	at android.view.View$PerformClick.run(View.java:28866)
        	at android.os.Handler.handleCallback(Handler.java:938)
        	at android.os.Handler.dispatchMessage(Handler.java:99)
        	at android.os.Looper.loop(Looper.java:264)
        	at android.app.ActivityThread.main(ActivityThread.java:8312)
        	at java.lang.reflect.Method.invoke(Native Method)
        	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:632)
        	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1049)

What device/emulator are you using?

Oppo reno 2f

Which Android version is your device/emulator running?

No response

Which version of the Oppia Android app are you using?

No response

Additional Context

Note: This is a subset of #5785 and fixing #5785 can also fully resolve this issue.

Root Cause When moving to the next card while audio is playing, changeDataSource() is called. After that, releaseMediaPlayer() is triggered once the loading spinner stops spinning. This sets prepared = false.

If the user clicks the play icon again, play() is invoked. Since it checks that prepared is false, an error is thrown: "Media Player not in a prepared state"

Proposed Solution

On clicking the play icon, first check the current network status.

  • If offline, show the offline dialog.
  • If the network status is fine, reinitialize the audio player before calling play().

For reference, see the existing implementation of handleAudioClick() for the action_audio_player icon in the toolbar.

Files to Investigate

subhajitxyz avatar Sep 08 '25 10:09 subhajitxyz

Pretty bad issue, but I don't think we need to block 0.16 on this.

BenHenning avatar Sep 08 '25 16:09 BenHenning

Hey, @subhajitxyz if the issue is still open, I would like to take this up

satnam-singh-JustCode avatar Sep 30 '25 12:09 satnam-singh-JustCode

Hi @subhajitxyz , I noticed the last request to work on this was from September. If this issue is still open, I would like to work on it. I have already set up the environment and successfully reproduced the crash locally.

Sandesh282 avatar Dec 11 '25 12:12 Sandesh282

Hi @Sandesh282, please feel free to work on this. It would be nice if you could share a summary of your proposed fix as well.

adhiamboperes avatar Dec 15 '25 13:12 adhiamboperes