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) {
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
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();

View File

@ -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;