fix OutgoingRinger crashes

Closes #5357
This commit is contained in:
Christian Ascheberg 2016-03-19 16:13:33 +01:00 committed by Moxie Marlinspike
parent cc1bfec08a
commit 13c1b15dc2

View File

@ -91,24 +91,19 @@ public class OutgoingRinger implements MediaPlayer.OnCompletionListener, MediaPl
mediaPlayer.setAudioStreamType(AudioManager.STREAM_VOICE_CALL);
mediaPlayer.setOnCompletionListener(this);
mediaPlayer.setOnPreparedListener(this);
mediaPlayer.setLooping(loopEnabled);
String packageName = context.getPackageName();
Uri dataUri = Uri.parse("android.resource://" + packageName + "/" + currentSoundID);
try {
mediaPlayer.setDataSource(context, dataUri);
mediaPlayer.prepareAsync();
} catch (IllegalArgumentException | SecurityException | IllegalStateException | IOException e) {
Log.w(TAG, e);
// TODO Auto-generated catch block
return;
}
try {
mediaPlayer.prepareAsync();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
Log.w(TAG, e);
return;
}
}
public void stop() {
@ -131,8 +126,6 @@ public class OutgoingRinger implements MediaPlayer.OnCompletionListener, MediaPl
}
public void onPrepared(MediaPlayer mp) {
mediaPlayer.setLooping(loopEnabled);
AudioManager am = ServiceUtil.getAudioManager(context);
if (am.isBluetoothScoAvailableOffCall()) {
@ -144,6 +137,10 @@ public class OutgoingRinger implements MediaPlayer.OnCompletionListener, MediaPl
}
}
mediaPlayer.start();
try {
mp.start();
} catch (IllegalStateException e) {
Log.w(TAG, e);
}
}
}