Release MediaPlayers immediately after stopping ringers

Closes #4987
// FREEBIE
This commit is contained in:
haffenloher 2015-12-29 00:35:03 +01:00 committed by Moxie Marlinspike
parent 1abf39685a
commit 1512f6e172
2 changed files with 6 additions and 5 deletions

View File

@ -56,7 +56,6 @@ public class IncomingRinger {
public IncomingRinger(Context context) { public IncomingRinger(Context context) {
this.context = context.getApplicationContext(); this.context = context.getApplicationContext();
vibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE); vibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
player = createPlayer();
} }
private MediaPlayer createPlayer() { private MediaPlayer createPlayer() {
@ -77,10 +76,8 @@ public class IncomingRinger {
public void start() { public void start() {
AudioManager audioManager = ServiceUtil.getAudioManager(context); AudioManager audioManager = ServiceUtil.getAudioManager(context);
if(player == null) { if (player != null) player.release();
//retry player creation to pick up changed ringtones or audio server restarts
player = createPlayer(); player = createPlayer();
}
int ringerMode = audioManager.getRingerMode(); int ringerMode = audioManager.getRingerMode();
@ -113,6 +110,8 @@ public class IncomingRinger {
if (player != null) { if (player != null) {
Log.d(TAG, "Stopping ringer"); Log.d(TAG, "Stopping ringer");
player.stop(); player.stop();
player.release();
player = null;
} }
Log.d(TAG, "Cancelling vibrator"); Log.d(TAG, "Cancelling vibrator");
vibrator.cancel(); vibrator.cancel();

View File

@ -115,6 +115,8 @@ public class OutgoingRinger implements MediaPlayer.OnCompletionListener, MediaPl
if( mediaPlayer == null ) return; if( mediaPlayer == null ) return;
try { try {
mediaPlayer.stop(); mediaPlayer.stop();
mediaPlayer.release();
mediaPlayer = null;
} catch( IllegalStateException e ) { } catch( IllegalStateException e ) {
} }
currentSoundID = -1; currentSoundID = -1;