android.media.VolumeProvider Java Examples
The following examples show how to use
android.media.VolumeProvider.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MediaSessionRecord.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
private void setVolumeTo(String packageName, int pid, int uid, ISessionControllerCallback caller, int value, int flags) { if (mVolumeType == PlaybackInfo.PLAYBACK_TYPE_LOCAL) { int stream = AudioAttributes.toLegacyStreamType(mAudioAttrs); mAudioManagerInternal.setStreamVolumeForUid(stream, value, flags, packageName, uid); } else { if (mVolumeControlType != VolumeProvider.VOLUME_CONTROL_ABSOLUTE) { // Nothing to do. The volume can't be set directly. return; } value = Math.max(0, Math.min(value, mMaxVolume)); mSessionCb.setVolumeTo(packageName, pid, uid, caller, value); int volumeBefore = (mOptimisticVolume < 0 ? mCurrentVolume : mOptimisticVolume); mOptimisticVolume = Math.max(0, Math.min(value, mMaxVolume)); mHandler.removeCallbacks(mClearOptimisticVolumeRunnable); mHandler.postDelayed(mClearOptimisticVolumeRunnable, OPTIMISTIC_VOLUME_TIMEOUT); if (volumeBefore != mOptimisticVolume) { pushVolumeUpdate(); } mService.notifyRemoteVolumeChanged(flags, this); if (DEBUG) { Log.d(TAG, "Set optimistic volume to " + mOptimisticVolume + " max is " + mMaxVolume); } } }
Example #2
Source File: VolumeProviderCompatApi21.java From adt-leanback-support with Apache License 2.0 | 5 votes |
public static Object createVolumeProvider(int volumeControl, int maxVolume, int currentVolume, final Delegate delegate) { return new VolumeProvider(volumeControl, maxVolume, currentVolume) { @Override public void onSetVolumeTo(int volume) { delegate.onSetVolumeTo(volume); } @Override public void onAdjustVolume(int direction) { delegate.onAdjustVolume(direction); } }; }
Example #3
Source File: MediaSessionRecord.java From android_9.0.0_r45 with Apache License 2.0 | 4 votes |
/** * Send a volume adjustment to the session owner. Direction must be one of * {@link AudioManager#ADJUST_LOWER}, {@link AudioManager#ADJUST_RAISE}, * {@link AudioManager#ADJUST_SAME}. * * @param packageName The package that made the original volume request. * @param pid The pid that made the original volume request. * @param uid The uid that made the original volume request. * @param caller caller binder. can be {@code null} if it's from the volume key. * @param asSystemService {@code true} if the event sent to the session as if it was come from * the system service instead of the app process. This helps sessions to distinguish * between the key injection by the app and key events from the hardware devices. * Should be used only when the volume key events aren't handled by foreground * activity. {@code false} otherwise to tell session about the real caller. * @param direction The direction to adjust volume in. * @param flags Any of the flags from {@link AudioManager}. * @param useSuggested True to use adjustSuggestedStreamVolume instead of */ public void adjustVolume(String packageName, int pid, int uid, ISessionControllerCallback caller, boolean asSystemService, int direction, int flags, boolean useSuggested) { int previousFlagPlaySound = flags & AudioManager.FLAG_PLAY_SOUND; if (isPlaybackActive() || hasFlag(MediaSession.FLAG_EXCLUSIVE_GLOBAL_PRIORITY)) { flags &= ~AudioManager.FLAG_PLAY_SOUND; } if (mVolumeType == PlaybackInfo.PLAYBACK_TYPE_LOCAL) { // Adjust the volume with a handler not to be blocked by other system service. int stream = AudioAttributes.toLegacyStreamType(mAudioAttrs); postAdjustLocalVolume(stream, direction, flags, packageName, uid, useSuggested, previousFlagPlaySound); } else { if (mVolumeControlType == VolumeProvider.VOLUME_CONTROL_FIXED) { // Nothing to do, the volume cannot be changed return; } if (direction == AudioManager.ADJUST_TOGGLE_MUTE || direction == AudioManager.ADJUST_MUTE || direction == AudioManager.ADJUST_UNMUTE) { Log.w(TAG, "Muting remote playback is not supported"); return; } mSessionCb.adjustVolume(packageName, pid, uid, caller, asSystemService, direction); int volumeBefore = (mOptimisticVolume < 0 ? mCurrentVolume : mOptimisticVolume); mOptimisticVolume = volumeBefore + direction; mOptimisticVolume = Math.max(0, Math.min(mOptimisticVolume, mMaxVolume)); mHandler.removeCallbacks(mClearOptimisticVolumeRunnable); mHandler.postDelayed(mClearOptimisticVolumeRunnable, OPTIMISTIC_VOLUME_TIMEOUT); if (volumeBefore != mOptimisticVolume) { pushVolumeUpdate(); } mService.notifyRemoteVolumeChanged(flags, this); if (DEBUG) { Log.d(TAG, "Adjusted optimistic volume to " + mOptimisticVolume + " max is " + mMaxVolume); } } }
Example #4
Source File: VolumeProviderCompatApi21.java From letv with Apache License 2.0 | 4 votes |
public static void setCurrentVolume(Object volumeProviderObj, int currentVolume) { ((VolumeProvider) volumeProviderObj).setCurrentVolume(currentVolume); }
Example #5
Source File: MediaSessionCompatApi21.java From adt-leanback-support with Apache License 2.0 | 4 votes |
public static void setPlaybackToRemote(Object sessionObj, Object volumeProviderObj) { ((MediaSession)sessionObj).setPlaybackToRemote((VolumeProvider)volumeProviderObj); }
Example #6
Source File: VolumeProviderCompatApi21.java From adt-leanback-support with Apache License 2.0 | 4 votes |
public static void setCurrentVolume(Object volumeProviderObj, int currentVolume) { ((VolumeProvider) volumeProviderObj).setCurrentVolume(currentVolume); }