Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8b28a7a0 authored by Alon Albert's avatar Alon Albert Committed by Android (Google) Code Review
Browse files

Merge "Use Audio Focus" into ics-ub-clock-amazon

parents a8c04cc2 205f02bc
Loading
Loading
Loading
Loading
+10 −1
Original line number Diff line number Diff line
@@ -41,7 +41,7 @@ import com.android.deskclock.provider.Alarm;
 * Manages alarms and vibe. Runs as a service so that it can continue to play
 * if another activity overrides the AlarmAlert dialog.
 */
public class AlarmKlaxon extends Service {
public class AlarmKlaxon extends Service implements AudioManager.OnAudioFocusChangeListener {
    // Default of 10 minutes until alarm is silenced.
    private static final String DEFAULT_ALARM_TIMEOUT = "10";

@@ -244,6 +244,8 @@ public class AlarmKlaxon extends Service {
            player.setAudioStreamType(AudioManager.STREAM_ALARM);
            player.setLooping(true);
            player.prepare();
            audioManager.requestAudioFocus(
                    this, AudioManager.STREAM_ALARM, AudioManager.AUDIOFOCUS_GAIN_TRANSIENT);
            player.start();
        }
    }
@@ -270,6 +272,9 @@ public class AlarmKlaxon extends Service {
            // Stop audio playing
            if (mMediaPlayer != null) {
                mMediaPlayer.stop();
                final AudioManager audioManager =
                        (AudioManager)getSystemService(Context.AUDIO_SERVICE);
                audioManager.abandonAudioFocus(this);
                mMediaPlayer.release();
                mMediaPlayer = null;
            }
@@ -304,4 +309,8 @@ public class AlarmKlaxon extends Service {
    }


    @Override
    public void onAudioFocusChange(int focusChange) {
        // Do nothing
    }
}
+10 −1
Original line number Diff line number Diff line
@@ -33,7 +33,7 @@ import android.telephony.TelephonyManager;
/**
 * Play the timer's ringtone. Will continue playing the same alarm until service is stopped.
 */
public class TimerRingService extends Service {
public class TimerRingService extends Service implements AudioManager.OnAudioFocusChangeListener {

    private boolean mPlaying = false;
    private MediaPlayer mMediaPlayer;
@@ -166,6 +166,8 @@ public class TimerRingService extends Service {
            player.setAudioStreamType(AudioManager.STREAM_ALARM);
            player.setLooping(true);
            player.prepare();
            audioManager.requestAudioFocus(
                    this, AudioManager.STREAM_ALARM, AudioManager.AUDIOFOCUS_GAIN_TRANSIENT);
            player.start();
        }
    }
@@ -191,6 +193,9 @@ public class TimerRingService extends Service {
            // Stop audio playing
            if (mMediaPlayer != null) {
                mMediaPlayer.stop();
                final AudioManager audioManager =
                        (AudioManager)getSystemService(Context.AUDIO_SERVICE);
                audioManager.abandonAudioFocus(this);
                mMediaPlayer.release();
                mMediaPlayer = null;
            }
@@ -198,4 +203,8 @@ public class TimerRingService extends Service {
    }


    @Override
    public void onAudioFocusChange(int focusChange) {
        // Do nothing
    }
}