summaryrefslogtreecommitdiffstats
path: root/packages/SystemUI/src/com/android/systemui/media
diff options
context:
space:
mode:
authorJean-Michel Trivi <jmtrivi@google.com>2014-08-06 16:32:38 -0700
committerJean-Michel Trivi <jmtrivi@google.com>2014-08-12 15:53:15 -0700
commit81f871e2b96125d57b76c07169e868e516443794 (patch)
tree6b28f2b5733357fb74e7a78a9826dec5d4f64821 /packages/SystemUI/src/com/android/systemui/media
parent8570ee6d6757025853666b0710386c2bad706b8d (diff)
downloadframeworks_base-81f871e2b96125d57b76c07169e868e516443794.zip
frameworks_base-81f871e2b96125d57b76c07169e868e516443794.tar.gz
frameworks_base-81f871e2b96125d57b76c07169e868e516443794.tar.bz2
Add support for AudioAttributes in android.media.Ringtone
Deprecate use of stream types. Map deprecated API to AudioAttributes. Add new methods to specify AudioAttributes on a Ringtone instance. Bug 16790748 Change-Id: Ifb3c2e838e1f119614459ad7d71d83a4d7c9ffdb
Diffstat (limited to 'packages/SystemUI/src/com/android/systemui/media')
-rw-r--r--packages/SystemUI/src/com/android/systemui/media/NotificationPlayer.java44
-rw-r--r--packages/SystemUI/src/com/android/systemui/media/RingtonePlayer.java13
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