diff options
author | Jean-Michel Trivi <jmtrivi@google.com> | 2014-08-13 15:53:24 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2014-08-12 23:14:35 +0000 |
commit | ceb4d418464d1b72c450c5e390b1cc7b1f92a49f (patch) | |
tree | c70773567e517f06e2640358d3b90a705ac1bb1f /packages/SystemUI/src | |
parent | e07465fafd66a6e882890febcd688e04e6cf2c61 (diff) | |
parent | 81f871e2b96125d57b76c07169e868e516443794 (diff) | |
download | frameworks_base-ceb4d418464d1b72c450c5e390b1cc7b1f92a49f.zip frameworks_base-ceb4d418464d1b72c450c5e390b1cc7b1f92a49f.tar.gz frameworks_base-ceb4d418464d1b72c450c5e390b1cc7b1f92a49f.tar.bz2 |
Merge "Add support for AudioAttributes in android.media.Ringtone" into lmp-dev
Diffstat (limited to 'packages/SystemUI/src')
-rw-r--r-- | packages/SystemUI/src/com/android/systemui/media/NotificationPlayer.java | 44 | ||||
-rw-r--r-- | packages/SystemUI/src/com/android/systemui/media/RingtonePlayer.java | 13 |
2 files changed, 45 insertions, 12 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/media/NotificationPlayer.java b/packages/SystemUI/src/com/android/systemui/media/NotificationPlayer.java index f8b347c..803a014 100644 --- a/packages/SystemUI/src/com/android/systemui/media/NotificationPlayer.java +++ b/packages/SystemUI/src/com/android/systemui/media/NotificationPlayer.java @@ -17,6 +17,7 @@ package com.android.systemui.media; import android.content.Context; +import android.media.AudioAttributes; import android.media.AudioManager; import android.media.MediaPlayer; import android.media.MediaPlayer.OnCompletionListener; @@ -45,11 +46,11 @@ public class NotificationPlayer implements OnCompletionListener { Context context; Uri uri; boolean looping; - int stream; + AudioAttributes attributes; long requestTime; public String toString() { - return "{ code=" + code + " looping=" + looping + " stream=" + stream + return "{ code=" + code + " looping=" + looping + " attributes=" + attributes + " uri=" + uri + " }"; } } @@ -79,7 +80,7 @@ public class NotificationPlayer implements OnCompletionListener { (AudioManager) mCmd.context.getSystemService(Context.AUDIO_SERVICE); try { MediaPlayer player = new MediaPlayer(); - player.setAudioStreamType(mCmd.stream); + player.setAudioAttributes(mCmd.attributes); player.setDataSource(mCmd.context, mCmd.uri); player.setLooping(mCmd.looping); player.prepare(); @@ -90,10 +91,12 @@ public class NotificationPlayer implements OnCompletionListener { if (mAudioManagerWithAudioFocus == null) { if (mDebug) Log.d(mTag, "requesting AudioFocus"); if (mCmd.looping) { - audioManager.requestAudioFocus(null, mCmd.stream, + audioManager.requestAudioFocus(null, + AudioAttributes.toLegacyStreamType(mCmd.attributes), AudioManager.AUDIOFOCUS_GAIN); } else { - audioManager.requestAudioFocus(null, mCmd.stream, + audioManager.requestAudioFocus(null, + AudioAttributes.toLegacyStreamType(mCmd.attributes), AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK); } mAudioManagerWithAudioFocus = audioManager; @@ -280,7 +283,9 @@ public class NotificationPlayer implements OnCompletionListener { * (see {@link MediaPlayer#setLooping(boolean)}) * @param stream the AudioStream to use. * (see {@link MediaPlayer#setAudioStreamType(int)}) + * @deprecated use {@link #play(Context, Uri, boolean, AudioAttributes)} instead. */ + @Deprecated public void play(Context context, Uri uri, boolean looping, int stream) { Command cmd = new Command(); cmd.requestTime = SystemClock.uptimeMillis(); @@ -288,7 +293,34 @@ public class NotificationPlayer implements OnCompletionListener { cmd.context = context; cmd.uri = uri; cmd.looping = looping; - cmd.stream = stream; + cmd.attributes = new AudioAttributes.Builder().setInternalLegacyStreamType(stream).build(); + synchronized (mCmdQueue) { + enqueueLocked(cmd); + mState = PLAY; + } + } + + /** + * Start playing the sound. It will actually start playing at some + * point in the future. There are no guarantees about latency here. + * Calling this before another audio file is done playing will stop + * that one and start the new one. + * + * @param context Your application's context. + * @param uri The URI to play. (see {@link MediaPlayer#setDataSource(Context, Uri)}) + * @param looping Whether the audio should loop forever. + * (see {@link MediaPlayer#setLooping(boolean)}) + * @param attributes the AudioAttributes to use. + * (see {@link MediaPlayer#setAudioAttributes(AudioAttributes)}) + */ + public void play(Context context, Uri uri, boolean looping, AudioAttributes attributes) { + Command cmd = new Command(); + cmd.requestTime = SystemClock.uptimeMillis(); + cmd.code = PLAY; + cmd.context = context; + cmd.uri = uri; + cmd.looping = looping; + cmd.attributes = attributes; synchronized (mCmdQueue) { enqueueLocked(cmd); mState = PLAY; diff --git a/packages/SystemUI/src/com/android/systemui/media/RingtonePlayer.java b/packages/SystemUI/src/com/android/systemui/media/RingtonePlayer.java index 5b4bb2c..7eed7f2 100644 --- a/packages/SystemUI/src/com/android/systemui/media/RingtonePlayer.java +++ b/packages/SystemUI/src/com/android/systemui/media/RingtonePlayer.java @@ -18,6 +18,7 @@ package com.android.systemui.media; import android.content.Context; import android.content.pm.PackageManager.NameNotFoundException; +import android.media.AudioAttributes; import android.media.IAudioService; import android.media.IRingtonePlayer; import android.media.Ringtone; @@ -71,11 +72,11 @@ public class RingtonePlayer extends SystemUI { private final IBinder mToken; private final Ringtone mRingtone; - public Client(IBinder token, Uri uri, UserHandle user, int streamType) { + public Client(IBinder token, Uri uri, UserHandle user, AudioAttributes aa) { mToken = token; mRingtone = new Ringtone(getContextForUser(user), false); - mRingtone.setStreamType(streamType); + mRingtone.setAudioAttributes(aa); mRingtone.setUri(uri); } @@ -91,7 +92,7 @@ public class RingtonePlayer extends SystemUI { private IRingtonePlayer mCallback = new IRingtonePlayer.Stub() { @Override - public void play(IBinder token, Uri uri, int streamType) throws RemoteException { + public void play(IBinder token, Uri uri, AudioAttributes aa) throws RemoteException { if (LOGD) { Log.d(TAG, "play(token=" + token + ", uri=" + uri + ", uid=" + Binder.getCallingUid() + ")"); @@ -101,7 +102,7 @@ public class RingtonePlayer extends SystemUI { client = mClients.get(token); if (client == null) { final UserHandle user = Binder.getCallingUserHandle(); - client = new Client(token, uri, user, streamType); + client = new Client(token, uri, user, aa); token.linkToDeath(client, 0); mClients.put(token, client); } @@ -137,13 +138,13 @@ public class RingtonePlayer extends SystemUI { } @Override - public void playAsync(Uri uri, UserHandle user, boolean looping, int streamType) { + public void playAsync(Uri uri, UserHandle user, boolean looping, AudioAttributes aa) { if (LOGD) Log.d(TAG, "playAsync(uri=" + uri + ", user=" + user + ")"); if (Binder.getCallingUid() != Process.SYSTEM_UID) { throw new SecurityException("Async playback only available from system UID."); } - mAsyncPlayer.play(getContextForUser(user), uri, looping, streamType); + mAsyncPlayer.play(getContextForUser(user), uri, looping, aa); } @Override |