diff options
author | Jean-Michel Trivi <jmtrivi@google.com> | 2014-06-26 12:05:16 -0700 |
---|---|---|
committer | Jean-Michel Trivi <jmtrivi@google.com> | 2014-07-01 16:45:29 +0000 |
commit | 8df982dfa5408afe67cd6a4b45bfbf26c94299d0 (patch) | |
tree | c0a9a65cbfc3de3c17b0f96f68b9d322b0d42b79 | |
parent | 2bd52dff6c96ace9c19e3e77068a45ea0d21c8fb (diff) | |
download | frameworks_base-8df982dfa5408afe67cd6a4b45bfbf26c94299d0.zip frameworks_base-8df982dfa5408afe67cd6a4b45bfbf26c94299d0.tar.gz frameworks_base-8df982dfa5408afe67cd6a4b45bfbf26c94299d0.tar.bz2 |
Java MediaPlayer: add support for setting audio attributes
Change-Id: Ia638107a5e67c20c46c2f5f1800db9da57d6f698
-rw-r--r-- | media/java/android/media/AudioAttributes.java | 34 | ||||
-rw-r--r-- | media/java/android/media/MediaPlayer.java | 30 | ||||
-rw-r--r-- | media/jni/android_media_MediaPlayer.cpp | 20 |
3 files changed, 78 insertions, 6 deletions
diff --git a/media/java/android/media/AudioAttributes.java b/media/java/android/media/AudioAttributes.java index 57c66da..d553d10 100644 --- a/media/java/android/media/AudioAttributes.java +++ b/media/java/android/media/AudioAttributes.java @@ -427,24 +427,46 @@ public final class AudioAttributes implements Parcelable { return 0; } + /** + * @hide + * Used to indicate that when parcelling, the tags should be parcelled through the flattened + * formatted string, not through the array of strings. + * Keep in sync with frameworks/av/media/libmediaplayerservice/MediaPlayerService.cpp + * see definition of kAudioAttributesMarshallTagFlattenTags + */ + public final static int FLATTEN_TAGS = 0x1; + /** + * When adding tags for writeToParcel(Parcel, int), add them in the list of flags (| NEW_FLAG) + */ + private final static int ALL_PARCEL_FLAGS = FLATTEN_TAGS; @Override public void writeToParcel(Parcel dest, int flags) { dest.writeInt(mUsage); dest.writeInt(mContentType); dest.writeInt(mFlags); - String[] tagsArray = new String[mTags.size()]; - mTags.toArray(tagsArray); - dest.writeStringArray(tagsArray); + dest.writeInt(flags & ALL_PARCEL_FLAGS); + if ((flags & FLATTEN_TAGS) == 0) { + String[] tagsArray = new String[mTags.size()]; + mTags.toArray(tagsArray); + dest.writeStringArray(tagsArray); + } else if ((flags & FLATTEN_TAGS) == FLATTEN_TAGS) { + dest.writeString(mFormattedTags); + } } private AudioAttributes(Parcel in) { mUsage = in.readInt(); mContentType = in.readInt(); mFlags = in.readInt(); + boolean hasFlattenedTags = ((in.readInt() & FLATTEN_TAGS) == FLATTEN_TAGS); mTags = new HashSet<String>(); - String[] tagsArray = in.readStringArray(); - for (int i = tagsArray.length - 1 ; i >= 0 ; i--) { - mTags.add(tagsArray[i]); + if (hasFlattenedTags) { + mTags.add(in.readString()); + } else { + String[] tagsArray = in.readStringArray(); + for (int i = tagsArray.length - 1 ; i >= 0 ; i--) { + mTags.add(tagsArray[i]); + } } } diff --git a/media/java/android/media/MediaPlayer.java b/media/java/android/media/MediaPlayer.java index d1909bc..490a8fd 100644 --- a/media/java/android/media/MediaPlayer.java +++ b/media/java/android/media/MediaPlayer.java @@ -1441,6 +1441,36 @@ public class MediaPlayer implements SubtitleController.Listener private native void _setAudioStreamType(int streamtype); + // Keep KEY_PARAMETER_* in sync with include/media/mediaplayer.h + private final static int KEY_PARAMETER_AUDIO_ATTRIBUTES = 1400; + /** + * Sets the parameter indicated by key. + * @param key key indicates the parameter to be set. + * @param value value of the parameter to be set. + * @return true if the parameter is set successfully, false otherwise + * {@hide} + */ + private native boolean setParameter(int key, Parcel value); + + /** + * @hide + * CANDIDATE FOR PUBLIC API + * Must call this method before prepare() or + * prepareAsync() in order for the audio attributes to become effective + * thereafter. + * @param attributes a non-null set of audio attributes + */ + public void setAudioAttributes(AudioAttributes attributes) throws IllegalArgumentException { + if (attributes == null) { + final String msg = "Cannot set audio attributes to null"; + throw new IllegalArgumentException(msg); + } + Parcel pattributes = Parcel.obtain(); + attributes.writeToParcel(pattributes, AudioAttributes.FLATTEN_TAGS); + setParameter(KEY_PARAMETER_AUDIO_ATTRIBUTES, pattributes); + pattributes.recycle(); + } + /** * Sets the player to be looping or non-looping. * diff --git a/media/jni/android_media_MediaPlayer.cpp b/media/jni/android_media_MediaPlayer.cpp index 6f42057..4587cf5 100644 --- a/media/jni/android_media_MediaPlayer.cpp +++ b/media/jni/android_media_MediaPlayer.cpp @@ -514,6 +514,25 @@ android_media_MediaPlayer_getAudioStreamType(JNIEnv *env, jobject thiz) return (jint) streamtype; } +static jboolean +android_media_MediaPlayer_setParameter(JNIEnv *env, jobject thiz, jint key, jobject java_request) +{ + ALOGV("setParameter: key %d", key); + sp<MediaPlayer> mp = getMediaPlayer(env, thiz); + if (mp == NULL ) { + jniThrowException(env, "java/lang/IllegalStateException", NULL); + return false; + } + + Parcel *request = parcelForJavaObject(env, java_request); + status_t err = mp->setParameter(key, *request); + if (err == OK) { + return true; + } else { + return false; + } +} + static void android_media_MediaPlayer_setLooping(JNIEnv *env, jobject thiz, jboolean looping) { @@ -857,6 +876,7 @@ static JNINativeMethod gMethods[] = { {"_reset", "()V", (void *)android_media_MediaPlayer_reset}, {"_setAudioStreamType", "(I)V", (void *)android_media_MediaPlayer_setAudioStreamType}, {"_getAudioStreamType", "()I", (void *)android_media_MediaPlayer_getAudioStreamType}, + {"setParameter", "(ILandroid/os/Parcel;)Z", (void *)android_media_MediaPlayer_setParameter}, {"setLooping", "(Z)V", (void *)android_media_MediaPlayer_setLooping}, {"isLooping", "()Z", (void *)android_media_MediaPlayer_isLooping}, {"_setVolume", "(FF)V", (void *)android_media_MediaPlayer_setVolume}, |