From 1512f6e172b1fd02664d5bea19f4da917a8e0a56 Mon Sep 17 00:00:00 2001 From: haffenloher Date: Tue, 29 Dec 2015 00:35:03 +0100 Subject: [PATCH] Release MediaPlayers immediately after stopping ringers Closes #4987 // FREEBIE --- src/org/thoughtcrime/redphone/audio/IncomingRinger.java | 9 ++++----- src/org/thoughtcrime/redphone/audio/OutgoingRinger.java | 2 ++ 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/org/thoughtcrime/redphone/audio/IncomingRinger.java b/src/org/thoughtcrime/redphone/audio/IncomingRinger.java index 9a96afb74d..57ab97d78d 100644 --- a/src/org/thoughtcrime/redphone/audio/IncomingRinger.java +++ b/src/org/thoughtcrime/redphone/audio/IncomingRinger.java @@ -56,7 +56,6 @@ public class IncomingRinger { public IncomingRinger(Context context) { this.context = context.getApplicationContext(); vibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE); - player = createPlayer(); } private MediaPlayer createPlayer() { @@ -77,10 +76,8 @@ public class IncomingRinger { public void start() { AudioManager audioManager = ServiceUtil.getAudioManager(context); - if(player == null) { - //retry player creation to pick up changed ringtones or audio server restarts - player = createPlayer(); - } + if (player != null) player.release(); + player = createPlayer(); int ringerMode = audioManager.getRingerMode(); @@ -113,6 +110,8 @@ public class IncomingRinger { if (player != null) { Log.d(TAG, "Stopping ringer"); player.stop(); + player.release(); + player = null; } Log.d(TAG, "Cancelling vibrator"); vibrator.cancel(); diff --git a/src/org/thoughtcrime/redphone/audio/OutgoingRinger.java b/src/org/thoughtcrime/redphone/audio/OutgoingRinger.java index 7890f9122b..de85a75263 100644 --- a/src/org/thoughtcrime/redphone/audio/OutgoingRinger.java +++ b/src/org/thoughtcrime/redphone/audio/OutgoingRinger.java @@ -115,6 +115,8 @@ public class OutgoingRinger implements MediaPlayer.OnCompletionListener, MediaPl if( mediaPlayer == null ) return; try { mediaPlayer.stop(); + mediaPlayer.release(); + mediaPlayer = null; } catch( IllegalStateException e ) { } currentSoundID = -1;