avoid IllegalStateException for CallActivity#stopCallingSound

This might happen sometimes. For now it's a try-catch instead trying to control the state of the mediaPlayer which could be quite difficult.

this will avoid the following exception:

    java.lang.IllegalStateException
    	at android.media.MediaPlayer.isPlaying(Native Method)
    	at com.nextcloud.talk.activities.CallActivity.stopCallingSound(CallActivity.java:2640)
    	at com.nextcloud.talk.activities.CallActivity.lambda$setCallState$31$com-nextcloud-talk-activities-CallActivity(CallActivity.java:2583)
    	at com.nextcloud.talk.activities.CallActivity$$ExternalSyntheticLambda7.run(Unknown Source:2)
    	at android.os.Handler.handleCallback(Handler.java:883)
    	at android.os.Handler.dispatchMessage(Handler.java:100)
    	at android.os.Looper.loop(Looper.java:237)
    	at android.app.ActivityThread.main(ActivityThread.java:8167)
    	at java.lang.reflect.Method.invoke(Native Method)
    	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:496)
    	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1100)

Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
Marcel Hibbe 2023-02-08 17:08:25 +01:00
parent a8225bfd27
commit bad8e2a705
No known key found for this signature in database
GPG key ID: C793F8B59F43CE7B

View file

@ -2593,14 +2593,20 @@ public class CallActivity extends CallBaseActivity {
private void stopCallingSound() {
if (mediaPlayer != null) {
try {
if (mediaPlayer.isPlaying()) {
mediaPlayer.stop();
}
} catch (IllegalStateException e) {
Log.e(TAG, "mediaPlayer was not initialized", e);
} finally {
if (mediaPlayer != null) {
mediaPlayer.release();
}
mediaPlayer = null;
}
}
}
/**
* Temporary implementation of SignalingMessageReceiver until signaling related code is extracted from