Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1433)

Unified Diff: media/base/android/java/src/org/chromium/media/AudioManagerAndroid.java

Issue 12974004: Add speaker on/off control on Android for WebRTC (Closed) Base URL: https://src.chromium.org/svn/trunk/src/
Patch Set: remove log Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « media/audio/audio_manager_base.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/base/android/java/src/org/chromium/media/AudioManagerAndroid.java
===================================================================
--- media/base/android/java/src/org/chromium/media/AudioManagerAndroid.java (revision 189667)
+++ media/base/android/java/src/org/chromium/media/AudioManagerAndroid.java (working copy)
@@ -4,7 +4,10 @@
package org.chromium.media;
+import android.content.BroadcastReceiver;
import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
import android.media.AudioManager;
import org.chromium.base.CalledByNative;
@@ -12,12 +15,54 @@
@JNINamespace("media")
class AudioManagerAndroid {
+ private static final String TAG = AudioManagerAndroid.class.getSimpleName();
+
+ private final AudioManager mAudioManager;
+ private final Context mContext;
+
+ private BroadcastReceiver mReceiver;
+ private boolean mOriginalSpeakerStatus;
+
@CalledByNative
- public static void setMode(Context context, int mode) {
- AudioManager audioManager =
- (AudioManager)context.getSystemService(Context.AUDIO_SERVICE);
- if (null != audioManager) {
- audioManager.setMode(mode);
+ public void setMode(int mode) {
+ mAudioManager.setMode(mode);
+ }
+
+ @CalledByNative
+ private static AudioManagerAndroid createAudioManagerAndroid(Context context) {
+ return new AudioManagerAndroid(context);
+ }
+
+ private AudioManagerAndroid(Context context) {
+ mContext = context;
+ mAudioManager = (AudioManager)mContext.getSystemService(Context.AUDIO_SERVICE);
+ }
+
+ @CalledByNative
+ public void registerHeadsetReceiver() {
+ if (mReceiver != null) {
+ return;
}
+
+ mOriginalSpeakerStatus = mAudioManager.isSpeakerphoneOn();
+ IntentFilter filter = new IntentFilter(Intent.ACTION_HEADSET_PLUG);
+
+ mReceiver = new BroadcastReceiver() {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ if (Intent.ACTION_HEADSET_PLUG.equals(intent.getAction())) {
+ mAudioManager.setSpeakerphoneOn(
+ intent.getIntExtra("state", 0) == 0);
+ }
+ }
+ };
+ mContext.registerReceiver(mReceiver, filter);
}
+
+ @CalledByNative
+ public void unregisterHeadsetReceiver() {
+ mContext.unregisterReceiver(mReceiver);
+ mReceiver = null;
+ mAudioManager.setSpeakerphoneOn(mOriginalSpeakerStatus);
+ }
}
« no previous file with comments | « media/audio/audio_manager_base.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698