List of usage examples for android.media AudioManager setStreamVolume
public void setStreamVolume(int streamType, int index, int flags)
From source file:com.kaltura.playersdk.PlayerViewController.java
private void setVolumeLevel(double percent) {//Itay AudioManager mgr = (AudioManager) mActivity.getSystemService(Context.AUDIO_SERVICE); if (percent > 0.01) { while (percent < 1.0) { percent *= 10;/*from ww w . ja v a2 s . c o m*/ } } mgr.setStreamVolume(AudioManager.STREAM_MUSIC, (int) percent, 0); }
From source file:im.vector.activity.CallViewActivity.java
/** * Init the buttons layer// w w w .ja v a 2 s . c o m */ private void manageSubViews() { // sanity check // the call could have been destroyed between call. if (null == mCall) { Log.d(LOG_TAG, "manageSubViews nothing to do"); return; } // initialize buttons if (null == mAcceptRejectLayout) { mAcceptRejectLayout = findViewById(R.id.layout_accept_reject); mAcceptButton = (Button) findViewById(R.id.accept_button); mRejectButton = (Button) findViewById(R.id.reject_button); mCancelButton = (Button) findViewById(R.id.cancel_button); mStopButton = (Button) findViewById(R.id.stop_button); mSpeakerSelectionView = (ImageView) findViewById(R.id.call_speaker_view); mCallStateTextView = (TextView) findViewById(R.id.call_state_text); mAcceptButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (null != mCall) { mCall.answer(); } } }); mRejectButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { onHangUp(); } }); mCancelButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { onHangUp(); } }); mStopButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { onHangUp(); } }); mSpeakerSelectionView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (null != mCall) { mCall.toggleSpeaker(); refreshSpeakerButton(); } } }); updateStateTextView("", false); } String callState = mCall.getCallState(); Log.d(LOG_TAG, "manageSubViews callState : " + callState); // hide / show avatar ImageView avatarView = (ImageView) CallViewActivity.this.findViewById(R.id.call_other_member); if (null != avatarView) { avatarView.setVisibility( (callState.equals(IMXCall.CALL_STATE_CONNECTED) && mCall.isVideo()) ? View.GONE : View.VISIBLE); } refreshSpeakerButton(); // display the button according to the call state if (callState.equals(IMXCall.CALL_STATE_ENDED)) { mAcceptRejectLayout.setVisibility(View.GONE); mCancelButton.setVisibility(View.GONE); mStopButton.setVisibility(View.GONE); } else if (callState.equals(IMXCall.CALL_STATE_CONNECTED)) { mAcceptRejectLayout.setVisibility(View.GONE); mCancelButton.setVisibility(View.GONE); mStopButton.setVisibility(View.VISIBLE); } else { mAcceptRejectLayout.setVisibility(mCall.isIncoming() ? View.VISIBLE : View.GONE); mCancelButton.setVisibility(mCall.isIncoming() ? View.GONE : View.VISIBLE); mStopButton.setVisibility(View.GONE); } // display the callview only when the preview is displayed if (mCall.isVideo() && !callState.equals(IMXCall.CALL_STATE_ENDED)) { int visibility; if (callState.equals(IMXCall.CALL_STATE_WAIT_CREATE_OFFER) || callState.equals(IMXCall.CALL_STATE_INVITE_SENT) || callState.equals(IMXCall.CALL_STATE_RINGING) || callState.equals(IMXCall.CALL_STATE_CREATE_ANSWER) || callState.equals(IMXCall.CALL_STATE_CONNECTING) || callState.equals(IMXCall.CALL_STATE_CONNECTED)) { visibility = View.VISIBLE; } else { visibility = View.GONE; } if ((null != mCall) && (visibility != mCall.getVisibility())) { mCall.setVisibility(visibility); } } // display the callstate if (callState.equals(IMXCall.CALL_STATE_CONNECTING) || callState.equals(IMXCall.CALL_STATE_CREATE_ANSWER) || callState.equals(IMXCall.CALL_STATE_WAIT_LOCAL_MEDIA) || callState.equals(IMXCall.CALL_STATE_WAIT_CREATE_OFFER)) { mAcceptButton.setAlpha(0.5f); mAcceptButton.setEnabled(false); updateStateTextView(getResources().getString(R.string.call_connecting), true); mCallStateTextView.setVisibility(View.VISIBLE); stopRinging(); } else if (callState.equals(IMXCall.CALL_STATE_CONNECTED)) { stopRinging(); CallViewActivity.this.runOnUiThread(new Runnable() { @Override public void run() { AudioManager audioManager = (AudioManager) CallViewActivity.this .getSystemService(Context.AUDIO_SERVICE); audioManager.setStreamVolume(AudioManager.STREAM_VOICE_CALL, mCallVolume, 0); MXCallsManager.setSpeakerphoneOn(CallViewActivity.this, mCall.isVideo()); refreshSpeakerButton(); } }); updateStateTextView(getResources().getString(R.string.call_connected), false); mCallStateTextView.setVisibility(mCall.isVideo() ? View.GONE : View.VISIBLE); } else if (callState.equals(IMXCall.CALL_STATE_ENDED)) { updateStateTextView(getResources().getString(R.string.call_ended), true); mCallStateTextView.setVisibility(View.VISIBLE); } else if (callState.equals(IMXCall.CALL_STATE_RINGING)) { if (mCall.isIncoming()) { if (mCall.isVideo()) { updateStateTextView(getResources().getString(R.string.incoming_video_call), true); } else { updateStateTextView(getResources().getString(R.string.incoming_voice_call), true); } } else { updateStateTextView(getResources().getString(R.string.call_ring), true); } mCallStateTextView.setVisibility(View.VISIBLE); if (mAutoAccept) { mAutoAccept = false; mAcceptButton.setAlpha(0.5f); mAcceptButton.setEnabled(false); mCallStateTextView.postDelayed(new Runnable() { @Override public void run() { mCall.answer(); } }, 100); } else { mAcceptButton.setAlpha(1.0f); mAcceptButton.setEnabled(true); if (mCall.isIncoming()) { startRinging(CallViewActivity.this); } else { startRingbackSound(CallViewActivity.this); } } } }
From source file:org.wso2.iot.agent.services.operation.OperationManager.java
/** * Mute the device.//from w w w . ja v a 2 s . c o m * * @param operation - Operation object. */ public void muteDevice(org.wso2.iot.agent.beans.Operation operation) { operation.setStatus(resources.getString(R.string.operation_value_completed)); resultBuilder.build(operation); AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); audioManager.setStreamVolume(AudioManager.STREAM_RING, DEFAULT_VOLUME, DEFAULT_FLAG); if (Constants.DEBUG_MODE_ENABLED) { Log.d(TAG, "Device muted"); } }
From source file:io.puzzlebox.orbit.ui.OrbitFragment.java
public void maximizeAudioVolume() { AudioManager audio = (AudioManager) getActivity().getSystemService(Context.AUDIO_SERVICE); int currentVolume = audio.getStreamVolume(AudioManager.STREAM_MUSIC); if (currentVolume < audio.getStreamMaxVolume(AudioManager.STREAM_MUSIC)) { Log.v(TAG, "Previous volume:" + currentVolume); Toast.makeText(getActivity().getApplicationContext(), "Automatically setting volume to maximum", Toast.LENGTH_SHORT).show(); AudioManager audioManager = (AudioManager) getActivity().getSystemService(Context.AUDIO_SERVICE); audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC), AudioManager.FLAG_SHOW_UI); }//from w ww .j av a 2s . com }
From source file:im.vector.activity.CallViewActivity.java
private void setMediaPlayerVolume(int percent) { if (percent < 0 || percent > 100) { Log.e(LOG_TAG, "setMediaPlayerVolume percent is invalid: " + percent); return;//from w w w . j a va 2s .c om } AudioManager audioManager = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE); mCallVolume = audioManager.getStreamVolume(AudioManager.STREAM_VOICE_CALL); int maxMusicVol = audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC); int maxVoiceVol = audioManager.getStreamMaxVolume(AudioManager.STREAM_VOICE_CALL); if (maxMusicVol > 0) { int volume = (int) ((float) percent / 100f * maxMusicVol); audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, volume, 0); volume = (int) ((float) percent / 100f * maxVoiceVol); audioManager.setStreamVolume(AudioManager.STREAM_VOICE_CALL, volume, 0); } Log.i(LOG_TAG, "Set media volume (ringback) to: " + audioManager.getStreamVolume(AudioManager.STREAM_MUSIC)); }
From source file:im.vector.activity.CallViewActivity.java
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { // assume that the user cancels the call if it is ringing if (keyCode == KeyEvent.KEYCODE_BACK) { if (!canCallBeResumed()) { if (null != mCall) { mCall.hangup(""); }//from ww w.j a v a2 s . c o m } else { saveCallView(); } } else if ((keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) || (keyCode == KeyEvent.KEYCODE_VOLUME_UP)) { // this is a trick to reduce the ring volume : // when the call is ringing, the AudioManager.Mode switch to MODE_IN_COMMUNICATION // so the volume is the next call one whereas the user expects to reduce the ring volume. if ((null != mCall) && mCall.getCallState().equals(IMXCall.CALL_STATE_RINGING)) { AudioManager audioManager = (AudioManager) CallViewActivity.this .getSystemService(Context.AUDIO_SERVICE); // IMXChrome call issue if (audioManager.getMode() == AudioManager.MODE_IN_COMMUNICATION) { int musicVol = audioManager.getStreamVolume(AudioManager.STREAM_VOICE_CALL) * audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC) / audioManager.getStreamMaxVolume(AudioManager.STREAM_VOICE_CALL); audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, musicVol, 0); } } } return super.onKeyDown(keyCode, event); }
From source file:com.nbplus.vbroadlauncher.RadioActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (Constants.OPEN_BETA_PHONE && LauncherSettings.getInstance(this).isSmartPhone()) { this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); }// w w w . j a va 2 s .c o m mSettingsContentObserver = new SettingsContentObserver(this, new Handler()); getApplicationContext().getContentResolver().registerContentObserver( android.provider.Settings.System.CONTENT_URI, true, mSettingsContentObserver); showProgressDialog(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { Window window = getWindow(); window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); window.setStatusBarColor(getResources().getColor(R.color.activity_radio_background)); } overridePendingTransition(R.anim.fade_in, R.anim.fade_out); setContentView(R.layout.activity_radio); Intent i = getIntent(); mShortcutData = i.getParcelableExtra(Constants.EXTRA_NAME_SHORTCUT_DATA); if (mShortcutData == null) { Log.e(TAG, "mShortcutData is not found.."); finishActivity(); return; } IntentFilter filter = new IntentFilter(); filter.addAction(MusicService.ACTION_PLAYED); filter.addAction(MusicService.ACTION_PAUSED); filter.addAction(MusicService.ACTION_STOPPED); filter.addAction(MusicService.ACTION_COMPLETED); filter.addAction(MusicService.ACTION_ERROR); filter.addAction(MusicService.ACTION_PLAYING_STATUS); LocalBroadcastManager.getInstance(this).registerReceiver(mBroadcastReceiver, filter); // send playing status Intent queryStatus = new Intent(this, MusicService.class); queryStatus.setAction(MusicService.ACTION_PLAYING_STATUS); startService(queryStatus); // ViewPager . // ??? ? ? ? . mViewPager = (NbplusViewPager) findViewById(R.id.viewPager); mIndicator = (CirclePageIndicator) findViewById(R.id.indicator); // close button ImageButton closeButton = (ImageButton) findViewById(R.id.btn_close); closeButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { finishActivity(); } }); mActivityLayout = (RelativeLayout) findViewById(R.id.radio_activity_background); int wallpaperId = LauncherSettings.getInstance(this).getWallpaperId(); mActivityLayout.setBackgroundResource(LauncherSettings.landWallpaperResource[wallpaperId]); // title. mRadioTitle = (TextView) findViewById(R.id.radio_activity_label); // media controller mPlayToggle = (ImageButton) findViewById(R.id.ic_media_control_play); mPlayToggle.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (mCurrentPlayingStatus == null) { return; } MusicService.State state = (MusicService.State) mCurrentPlayingStatus .getSerializable(MusicService.EXTRA_PLAYING_STATUS); Intent i = new Intent(RadioActivity.this, MusicService.class); if (state == MusicService.State.Playing) { i.setAction(MusicService.ACTION_PAUSE); } else if (state == MusicService.State.Paused) { i.setAction(MusicService.ACTION_PLAY); } startService(i); } }); mPlayStop = (ImageButton) findViewById(R.id.ic_media_control_stop); mPlayStop.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (mCurrentPlayingStatus == null) { return; } MusicService.State state = (MusicService.State) mCurrentPlayingStatus .getSerializable(MusicService.EXTRA_PLAYING_STATUS); if (state == MusicService.State.Playing || state == MusicService.State.Paused) { Intent i = new Intent(RadioActivity.this, MusicService.class); i.setAction(MusicService.ACTION_STOP); i.putExtra(MusicService.EXTRA_MUSIC_FORCE_STOP, false); startService(i); } } }); mSoundToggle = (ImageButton) findViewById(R.id.ic_media_control_volume_btn); AudioManager audio = (AudioManager) getSystemService(Context.AUDIO_SERVICE); int currentVolume = audio.getStreamVolume(AudioManager.STREAM_MUSIC); int maxVolume = audio.getStreamMaxVolume(AudioManager.STREAM_MUSIC); if (currentVolume <= 0) { mSoundToggle.setBackgroundResource(R.drawable.ic_button_radio_sound_off); } else { mSoundToggle.setBackgroundResource(R.drawable.ic_button_radio_sound_on); } mSoundToggle.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { AudioManager audio = (AudioManager) getSystemService(Context.AUDIO_SERVICE); if (audio.getStreamVolume(AudioManager.STREAM_MUSIC) <= 0) { if (mSoundTogglePreviousValue > 0) { audio.setStreamVolume(AudioManager.STREAM_MUSIC, mSoundTogglePreviousValue, AudioManager.FLAG_PLAY_SOUND); } else { mSoundTogglePreviousValue = 1; audio.setStreamVolume(AudioManager.STREAM_MUSIC, mSoundTogglePreviousValue, AudioManager.FLAG_PLAY_SOUND); } mSoundToggle.setBackgroundResource(R.drawable.ic_button_radio_sound_on); mSeekbar.setProgress(mSoundTogglePreviousValue); mSoundTogglePreviousValue = -1; } else { mSoundTogglePreviousValue = audio.getStreamVolume(AudioManager.STREAM_MUSIC); audio.setStreamVolume(AudioManager.STREAM_MUSIC, 0, AudioManager.FLAG_PLAY_SOUND); mSoundToggle.setBackgroundResource(R.drawable.ic_button_radio_sound_off); } } }); mSeekbar = (SeekBar) findViewById(R.id.ic_media_control_volume_seek); mSeekbar.setMax(maxVolume); mSeekbar.setProgress(currentVolume); mSeekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { if (fromUser) { mSoundTogglePreviousValue = -1; AudioManager audio = (AudioManager) getSystemService(Context.AUDIO_SERVICE); audio.setStreamVolume(AudioManager.STREAM_MUSIC, progress, AudioManager.FLAG_PLAY_SOUND); } } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(SeekBar seekBar) { } }); getRadioChannelTask = new GetRadioChannelTask(); if (getRadioChannelTask != null) { getRadioChannelTask.setBroadcastApiData(this, mHandler, mShortcutData.getDomain() + mShortcutData.getPath()); mIsExecuteGetRadioChannelTask = true; getRadioChannelTask.execute(); } }
From source file:com.wso2.mobile.mdm.services.Operation.java
/** * Mute the device/*ww w . j av a2s. co m*/ */ private void muteDevice() { Log.v("MUTING THE DEVICE : ", "MUTING"); AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); Log.v("VOLUME : ", "" + audioManager.getStreamVolume(AudioManager.STREAM_RING)); audioManager.setStreamVolume(AudioManager.STREAM_RING, 0, 0); Log.v("VOLUME AFTER: ", "" + audioManager.getStreamVolume(AudioManager.STREAM_RING)); }
From source file:org.drrickorang.loopback.LoopbackActivity.java
/** * In the case where the test is started through adb command, this method will change the * settings if any parameter is specified. *//*from ww w . ja v a2s . co m*/ private void runIntentTest() { // mIntentRunning == true if test is started through adb command. if (mIntentRunning) { if (mIntentBufferTestDuration > 0) { getApp().setBufferTestDuration(mIntentBufferTestDuration); } if (mIntentAudioLevel >= 0) { AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE); am.setStreamVolume(AudioManager.STREAM_MUSIC, mIntentAudioLevel, 0); } if (mIntentSamplingRate != 0) { getApp().setSamplingRate(mIntentSamplingRate); } if (mIntentMicSource >= 0) { getApp().setMicSource(mIntentMicSource); } if (mIntentAudioThread >= 0) { getApp().setAudioThreadType(mIntentAudioThread); getApp().computeDefaults(); } int bytesPerFrame = Constant.BYTES_PER_FRAME; if (mIntentRecorderBuffer > 0) { getApp().setRecorderBufferSizeInBytes(mIntentRecorderBuffer * bytesPerFrame); } if (mIntentPlayerBuffer > 0) { getApp().setPlayerBufferSizeInBytes(mIntentPlayerBuffer * bytesPerFrame); } refreshState(); if (mIntentTestType >= 0) { switch (mIntentTestType) { case Constant.LOOPBACK_PLUG_AUDIO_THREAD_TEST_TYPE_LATENCY: startLatencyTest(); break; case Constant.LOOPBACK_PLUG_AUDIO_THREAD_TEST_TYPE_BUFFER_PERIOD: startBufferTest(); break; default: assert (false); } } else { // if test type is not specified in command, just run latency test startLatencyTest(); } } }
From source file:io.puzzlebox.orbit.ui.OrbitFragment.java
public void playControl() { Log.d(TAG, "playControl()"); // TODO Convert to service // FragmentTabAdvanced fragmentAdvanced = // (FragmentTabAdvanced) getActivity().getSupportFragmentManager().findFragmentByTag( getTabFragmentAdvanced() ); ////from w ww . ja v a2 s . co m if (OrbitSingleton.getInstance().generateAudio) { /** * Generate signal on the fly */ // // Handle controlled descent thread if activated // if ((fragmentAdvanced.orbitControlledDescentTask != null) && // (fragmentAdvanced.orbitControlledDescentTask.keepDescending)) { // fragmentAdvanced.orbitControlledDescentTask.callStopAudio = false; // fragmentAdvanced.orbitControlledDescentTask.keepDescending = false; // } // if (audioHandler != null) { // serviceBinder.ifFlip = fragmentAdvanced.checkBoxInvertControlSignal.isChecked(); // if checked then flip OrbitSingleton.getInstance().audioHandler.ifFlip = OrbitSingleton.getInstance().invertControlSignal; // if checked then flip int channel = 0; // default "A" // if (fragmentAdvanced != null) // channel = fragmentAdvanced.radioGroupChannel.getCheckedRadioButtonId(); // if (demoFlightMode) // updateAudioHandlerLoopNumberWhileMindControl(200); // else // updateAudioHandlerLoopNumberWhileMindControl(4500); // // updateAudioHandlerLoopNumberWhileMindControl(5000); updateAudioHandlerLoopNumberWhileMindControl(-1); // Loop infinite for easier user testing updateAudioHandlerChannel(channel); OrbitSingleton.getInstance().audioHandler.mutexNotify(); // } // // } else { /** * Play audio control file */ /** Getting the user sound settings */ AudioManager audioManager = (AudioManager) getActivity().getSystemService(Context.AUDIO_SERVICE); // float actualVolume = (float) audioManager.getStreamVolume(AudioManager.STREAM_MUSIC); float maxVolume = (float) audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC); // float volume = actualVolume / maxVolume; audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, (int) maxVolume, 0); /** Is the sound loaded already? */ if (OrbitSingleton.getInstance().loaded) { // soundPool.play(soundID, volume, volume, 1, 0, 1f); // soundPool.setVolume(soundID, 1f, 1f); // soundPool.play(soundID, maxVolume, maxVolume, 1, 0, 1f); // Fixes Samsung Galaxy S4 [SGH-M919] OrbitSingleton.getInstance().soundPool.play(OrbitSingleton.getInstance().soundID, 1f, 1f, 1, 0, 1f); // Fixes Samsung Galaxy S4 [SGH-M919] // TODO No visible effects of changing these variables on digital oscilloscope // soundPool.play(soundID, 0.5f, 0.5f, 1, 0, 0.5f); // if (DEBUG) Log.v(TAG, "Played sound"); } } }