Skip to content

Commit c6c4365

Browse files
committed
Implement android.media.AudioManager.getProperty()
Bug: 6635041 Change-Id: I0e7d53b99559cdc89f2f107f23048e4b1a8dd383
1 parent 282c51d commit c6c4365

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

core/jni/android_media_AudioSystem.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,18 @@ android_media_AudioSystem_getDevicesForStream(JNIEnv *env, jobject thiz, jint st
242242
return (jint) AudioSystem::getDevicesForStream(static_cast <audio_stream_type_t>(stream));
243243
}
244244

245+
static jint
246+
android_media_AudioSystem_getPrimaryOutputSamplingRate(JNIEnv *env, jobject clazz)
247+
{
248+
return (jint) AudioSystem::getPrimaryOutputSamplingRate();
249+
}
250+
251+
static jint
252+
android_media_AudioSystem_getPrimaryOutputFrameCount(JNIEnv *env, jobject clazz)
253+
{
254+
return (jint) AudioSystem::getPrimaryOutputFrameCount();
255+
}
256+
245257
// ----------------------------------------------------------------------------
246258

247259
static JNINativeMethod gMethods[] = {
@@ -263,6 +275,8 @@ static JNINativeMethod gMethods[] = {
263275
{"setMasterMute", "(Z)I", (void *)android_media_AudioSystem_setMasterMute},
264276
{"getMasterMute", "()Z", (void *)android_media_AudioSystem_getMasterMute},
265277
{"getDevicesForStream", "(I)I", (void *)android_media_AudioSystem_getDevicesForStream},
278+
{"getPrimaryOutputSamplingRate", "()I", (void *)android_media_AudioSystem_getPrimaryOutputSamplingRate},
279+
{"getPrimaryOutputFrameCount", "()I", (void *)android_media_AudioSystem_getPrimaryOutputFrameCount},
266280
};
267281

268282
int register_android_media_AudioSystem(JNIEnv *env)

media/java/android/media/AudioManager.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2474,8 +2474,16 @@ public IRingtonePlayer getRingtonePlayer() {
24742474
* or null if there is no value for that key.
24752475
*/
24762476
public String getProperty(String key) {
2477-
// implementation to be written
2478-
return null;
2477+
if (PROPERTY_OUTPUT_SAMPLE_RATE.equals(key)) {
2478+
int outputSampleRate = AudioSystem.getPrimaryOutputSamplingRate();
2479+
return outputSampleRate > 0 ? Integer.toString(outputSampleRate) : null;
2480+
} else if (PROPERTY_OUTPUT_FRAMES_PER_BUFFER.equals(key)) {
2481+
int outputFramesPerBuffer = AudioSystem.getPrimaryOutputFrameCount();
2482+
return outputFramesPerBuffer > 0 ? Integer.toString(outputFramesPerBuffer) : null;
2483+
} else {
2484+
// null or unknown key
2485+
return null;
2486+
}
24792487
}
24802488

24812489
}

media/java/android/media/AudioSystem.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,4 +381,9 @@ public static String getDeviceName(int device)
381381
public static native int setMasterMute(boolean mute);
382382
public static native boolean getMasterMute();
383383
public static native int getDevicesForStream(int stream);
384+
385+
// helpers for android.media.AudioManager.getProperty(), see description there for meaning
386+
public static native int getPrimaryOutputSamplingRate();
387+
public static native int getPrimaryOutputFrameCount();
388+
384389
}

0 commit comments

Comments
 (0)