- /* play audio alert */
- if (mAlert == null) {
- Log.e("Unable to play alarm: no audio file available");
- } else {
- /* we need a new MediaPlayer when we change media URLs */
- mMediaPlayer = new MediaPlayer();
- mMediaPlayer.setOnErrorListener(new OnErrorListener() {
- public boolean onError(MediaPlayer mp, int what, int extra) {
- Log.e("Error occurred while playing audio.");
- mp.stop();
- mp.release();
- mMediaPlayer = null;
- return true;
- }
- });
-
- try {
+ // TODO: Reuse mMediaPlayer instead of creating a new one and/or use
+ // RingtoneManager.
+ mMediaPlayer = new MediaPlayer();
+ mMediaPlayer.setOnErrorListener(new OnErrorListener() {
+ public boolean onError(MediaPlayer mp, int what, int extra) {
+ Log.e("Error occurred while playing audio.");
+ mp.stop();
+ mp.release();
+ mMediaPlayer = null;
+ return true;
+ }
+ });
+
+ try {
+ TelephonyManager tm = (TelephonyManager) context.getSystemService(
+ Context.TELEPHONY_SERVICE);
+ // Check if we are in a call. If we are, use the in-call alarm
+ // resource at a low volume to not disrupt the call.
+ if (tm.getCallState() != TelephonyManager.CALL_STATE_IDLE) {
+ Log.v("Using the in-call alarm");
+ mMediaPlayer.setVolume(IN_CALL_VOLUME, IN_CALL_VOLUME);
+ setDataSourceFromResource(context.getResources(),
+ mMediaPlayer, R.raw.in_call_alarm);
+ } else {