diff options
| -rw-r--r-- | core/java/android/widget/VideoView.java | 11 | ||||
| -rw-r--r-- | media/java/android/media/AudioManager.java | 65 |
2 files changed, 42 insertions, 34 deletions
diff --git a/core/java/android/widget/VideoView.java b/core/java/android/widget/VideoView.java index 9d6ba57..2671739 100644 --- a/core/java/android/widget/VideoView.java +++ b/core/java/android/widget/VideoView.java @@ -302,6 +302,8 @@ public class VideoView extends SurfaceView mMediaPlayer = null; mCurrentState = STATE_IDLE; mTargetState = STATE_IDLE; + AudioManager am = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE); + am.abandonAudioFocus(null); } } @@ -310,12 +312,13 @@ public class VideoView extends SurfaceView // not ready for playback just yet, will try again later return; } - AudioManager am = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE); - am.requestAudioFocus(null, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN); - // we shouldn't clear the target state, because somebody might have // called start() previously release(false); + + AudioManager am = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE); + am.requestAudioFocus(null, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN); + try { mMediaPlayer = new MediaPlayer(); // TODO: create SubtitleController in MediaPlayer, but we need @@ -641,6 +644,8 @@ public class VideoView extends SurfaceView if (cleartargetstate) { mTargetState = STATE_IDLE; } + AudioManager am = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE); + am.abandonAudioFocus(null); } } diff --git a/media/java/android/media/AudioManager.java b/media/java/android/media/AudioManager.java index db67fbf..85aaf4c 100644 --- a/media/java/android/media/AudioManager.java +++ b/media/java/android/media/AudioManager.java @@ -56,7 +56,7 @@ import java.util.Iterator; */ public class AudioManager { - private final Context mContext; + private final Context mApplicationContext; private long mVolumeKeyUpTime; private final boolean mUseVolumeKeySounds; private final boolean mUseFixedVolume; @@ -575,10 +575,10 @@ public class AudioManager { * @hide */ public AudioManager(Context context) { - mContext = context; - mUseVolumeKeySounds = mContext.getResources().getBoolean( + mApplicationContext = context; + mUseVolumeKeySounds = mApplicationContext.getResources().getBoolean( com.android.internal.R.bool.config_useVolumeKeySounds); - mUseFixedVolume = mContext.getResources().getBoolean( + mUseFixedVolume = mApplicationContext.getResources().getBoolean( com.android.internal.R.bool.config_useFixedVolume); sAudioPortEventHandler.init(); } @@ -617,7 +617,7 @@ public class AudioManager { * or {@link KeyEvent#KEYCODE_MEDIA_AUDIO_TRACK}. */ public void dispatchMediaKeyEvent(KeyEvent keyEvent) { - MediaSessionLegacyHelper helper = MediaSessionLegacyHelper.getHelper(mContext); + MediaSessionLegacyHelper helper = MediaSessionLegacyHelper.getHelper(mApplicationContext); helper.sendMediaButtonEvent(keyEvent, false); } @@ -663,7 +663,8 @@ public class AudioManager { break; case KeyEvent.KEYCODE_VOLUME_MUTE: if (event.getRepeatCount() == 0) { - MediaSessionLegacyHelper.getHelper(mContext).sendVolumeKeyEvent(event, false); + MediaSessionLegacyHelper.getHelper(mApplicationContext) + .sendVolumeKeyEvent(event, false); } break; } @@ -690,7 +691,8 @@ public class AudioManager { mVolumeKeyUpTime = SystemClock.uptimeMillis(); break; case KeyEvent.KEYCODE_VOLUME_MUTE: - MediaSessionLegacyHelper.getHelper(mContext).sendVolumeKeyEvent(event, false); + MediaSessionLegacyHelper.getHelper(mApplicationContext) + .sendVolumeKeyEvent(event, false); break; } } @@ -735,7 +737,7 @@ public class AudioManager { IAudioService service = getService(); try { service.adjustStreamVolume(streamType, direction, flags, - mContext.getOpPackageName()); + mApplicationContext.getOpPackageName()); } catch (RemoteException e) { Log.e(TAG, "Dead object in adjustStreamVolume", e); } @@ -765,7 +767,7 @@ public class AudioManager { * @see #isVolumeFixed() */ public void adjustVolume(int direction, int flags) { - MediaSessionLegacyHelper helper = MediaSessionLegacyHelper.getHelper(mContext); + MediaSessionLegacyHelper helper = MediaSessionLegacyHelper.getHelper(mApplicationContext); helper.sendAdjustVolumeBy(USE_DEFAULT_STREAM_TYPE, direction, flags); } @@ -794,7 +796,7 @@ public class AudioManager { * @see #isVolumeFixed() */ public void adjustSuggestedStreamVolume(int direction, int suggestedStreamType, int flags) { - MediaSessionLegacyHelper helper = MediaSessionLegacyHelper.getHelper(mContext); + MediaSessionLegacyHelper helper = MediaSessionLegacyHelper.getHelper(mApplicationContext); helper.sendAdjustVolumeBy(suggestedStreamType, direction, flags); } @@ -802,7 +804,7 @@ public class AudioManager { public void setMasterMute(boolean mute, int flags) { IAudioService service = getService(); try { - service.setMasterMute(mute, flags, mContext.getOpPackageName()); + service.setMasterMute(mute, flags, mApplicationContext.getOpPackageName()); } catch (RemoteException e) { Log.e(TAG, "Dead object in setMasterMute", e); } @@ -931,7 +933,7 @@ public class AudioManager { } IAudioService service = getService(); try { - service.setRingerModeExternal(ringerMode, mContext.getOpPackageName()); + service.setRingerModeExternal(ringerMode, mApplicationContext.getOpPackageName()); } catch (RemoteException e) { Log.e(TAG, "Dead object in setRingerMode", e); } @@ -952,7 +954,7 @@ public class AudioManager { public void setStreamVolume(int streamType, int index, int flags) { IAudioService service = getService(); try { - service.setStreamVolume(streamType, index, flags, mContext.getOpPackageName()); + service.setStreamVolume(streamType, index, flags, mApplicationContext.getOpPackageName()); } catch (RemoteException e) { Log.e(TAG, "Dead object in setStreamVolume", e); } @@ -1265,7 +1267,7 @@ public class AudioManager { * @see #startBluetoothSco() */ public boolean isBluetoothScoAvailableOffCall() { - return mContext.getResources().getBoolean( + return mApplicationContext.getResources().getBoolean( com.android.internal.R.bool.config_bluetooth_sco_off_call); } @@ -1317,7 +1319,8 @@ public class AudioManager { public void startBluetoothSco(){ IAudioService service = getService(); try { - service.startBluetoothSco(mICallBack, mContext.getApplicationInfo().targetSdkVersion); + service.startBluetoothSco(mICallBack, + mApplicationContext.getApplicationInfo().targetSdkVersion); } catch (RemoteException e) { Log.e(TAG, "Dead object in startBluetoothSco", e); } @@ -1465,7 +1468,7 @@ public class AudioManager { public void setMicrophoneMute(boolean on){ IAudioService service = getService(); try { - service.setMicrophoneMute(on, mContext.getOpPackageName()); + service.setMicrophoneMute(on, mApplicationContext.getOpPackageName()); } catch (RemoteException e) { Log.e(TAG, "Dead object in setMicrophoneMute", e); } @@ -1498,7 +1501,7 @@ public class AudioManager { public void setMode(int mode) { IAudioService service = getService(); try { - service.setMode(mode, mICallBack, mContext.getOpPackageName()); + service.setMode(mode, mICallBack, mApplicationContext.getOpPackageName()); } catch (RemoteException e) { Log.e(TAG, "Dead object in setMode", e); } @@ -1896,7 +1899,7 @@ public class AudioManager { * Settings has an in memory cache, so this is fast. */ private boolean querySoundEffectsEnabled(int user) { - return Settings.System.getIntForUser(mContext.getContentResolver(), + return Settings.System.getIntForUser(mApplicationContext.getContentResolver(), Settings.System.SOUND_EFFECTS_ENABLED, 0, user) != 0; } @@ -2308,7 +2311,7 @@ public class AudioManager { try { status = service.requestAudioFocus(requestAttributes, durationHint, mICallBack, mAudioFocusDispatcher, getIdForAudioFocusListener(l), - mContext.getOpPackageName() /* package name */, flags, + mApplicationContext.getOpPackageName() /* package name */, flags, ap != null ? ap.cb() : null); } catch (RemoteException e) { Log.e(TAG, "Can't call requestAudioFocus() on AudioService:", e); @@ -2333,7 +2336,7 @@ public class AudioManager { .setInternalLegacyStreamType(streamType).build(), durationHint, mICallBack, null, AudioSystem.IN_VOICE_COMM_FOCUS_ID, - mContext.getOpPackageName(), + mApplicationContext.getOpPackageName(), AUDIOFOCUS_FLAG_LOCK, null /* policy token */); } catch (RemoteException e) { @@ -2402,7 +2405,7 @@ public class AudioManager { if (eventReceiver == null) { return; } - if (!eventReceiver.getPackageName().equals(mContext.getPackageName())) { + if (!eventReceiver.getPackageName().equals(mApplicationContext.getPackageName())) { Log.e(TAG, "registerMediaButtonEventReceiver() error: " + "receiver and context package names don't match"); return; @@ -2411,7 +2414,7 @@ public class AudioManager { Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON); // the associated intent will be handled by the component being registered mediaButtonIntent.setComponent(eventReceiver); - PendingIntent pi = PendingIntent.getBroadcast(mContext, + PendingIntent pi = PendingIntent.getBroadcast(mApplicationContext, 0/*requestCode, ignored*/, mediaButtonIntent, 0/*flags*/); registerMediaButtonIntent(pi, eventReceiver); } @@ -2445,8 +2448,8 @@ public class AudioManager { Log.e(TAG, "Cannot call registerMediaButtonIntent() with a null parameter"); return; } - MediaSessionLegacyHelper helper = MediaSessionLegacyHelper.getHelper(mContext); - helper.addMediaButtonListener(pi, eventReceiver, mContext); + MediaSessionLegacyHelper helper = MediaSessionLegacyHelper.getHelper(mApplicationContext); + helper.addMediaButtonListener(pi, eventReceiver, mApplicationContext); } /** @@ -2464,7 +2467,7 @@ public class AudioManager { Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON); // the associated intent will be handled by the component being registered mediaButtonIntent.setComponent(eventReceiver); - PendingIntent pi = PendingIntent.getBroadcast(mContext, + PendingIntent pi = PendingIntent.getBroadcast(mApplicationContext, 0/*requestCode, ignored*/, mediaButtonIntent, 0/*flags*/); unregisterMediaButtonIntent(pi); } @@ -2487,7 +2490,7 @@ public class AudioManager { * @hide */ public void unregisterMediaButtonIntent(PendingIntent pi) { - MediaSessionLegacyHelper helper = MediaSessionLegacyHelper.getHelper(mContext); + MediaSessionLegacyHelper helper = MediaSessionLegacyHelper.getHelper(mApplicationContext); helper.removeMediaButtonListener(pi); } @@ -2504,7 +2507,7 @@ public class AudioManager { if ((rcClient == null) || (rcClient.getRcMediaIntent() == null)) { return; } - rcClient.registerWithSession(MediaSessionLegacyHelper.getHelper(mContext)); + rcClient.registerWithSession(MediaSessionLegacyHelper.getHelper(mApplicationContext)); } /** @@ -2519,7 +2522,7 @@ public class AudioManager { if ((rcClient == null) || (rcClient.getRcMediaIntent() == null)) { return; } - rcClient.unregisterWithSession(MediaSessionLegacyHelper.getHelper(mContext)); + rcClient.unregisterWithSession(MediaSessionLegacyHelper.getHelper(mApplicationContext)); } /** @@ -3038,7 +3041,7 @@ public class AudioManager { IAudioService service = getService(); try { service.setWiredDeviceConnectionState(type, state, address, name, - mContext.getOpPackageName()); + mApplicationContext.getOpPackageName()); } catch (RemoteException e) { Log.e(TAG, "Dead object in setWiredDeviceConnectionState "+e); } @@ -3182,7 +3185,7 @@ public class AudioManager { */ public void disableSafeMediaVolume() { try { - getService().disableSafeMediaVolume(mContext.getOpPackageName()); + getService().disableSafeMediaVolume(mApplicationContext.getOpPackageName()); } catch (RemoteException e) { Log.w(TAG, "Error disabling safe media volume", e); } @@ -3194,7 +3197,7 @@ public class AudioManager { */ public void setRingerModeInternal(int ringerMode) { try { - getService().setRingerModeInternal(ringerMode, mContext.getOpPackageName()); + getService().setRingerModeInternal(ringerMode, mApplicationContext.getOpPackageName()); } catch (RemoteException e) { Log.w(TAG, "Error calling setRingerModeInternal", e); } |
