List of usage examples for android.media AudioManager getStreamMaxVolume
public int getStreamMaxVolume(int streamType)
From source file:com.googlecode.mindbell.accessors.ContextAccessor.java
public int getAlarmMaxVolume() { AudioManager audioMan = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); return audioMan.getStreamMaxVolume(AudioManager.STREAM_ALARM); }
From source file:com.intel.xdk.player.Player.java
public void setAudioVolume(String volume) { //Valid volumes 0.0 to 1.0 double castVol = Float.parseFloat(volume); if (castVol > 1.0) castVol = 1.0;//from www .j av a 2s . co m // Get the AudioManager AudioManager audioManager = (AudioManager) activity.getSystemService(Context.AUDIO_SERVICE); int newVol = (int) (audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC) * castVol); // Set the volume of played media to maximum. audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, newVol, 0); String js = "javascript: var e = document.createEvent('Events');e.initEvent('intel.xdk.player.audio.volume.set',true,true);document.dispatchEvent(e);"; injectJS(js); }
From source file:com.intel.xdk.player.Player.java
public void playSoundById(final int id) { AudioManager mgr = (AudioManager) activity.getSystemService(Context.AUDIO_SERVICE); int streamVolume = mgr.getStreamVolume(AudioManager.STREAM_MUSIC); int streamMaximum = mgr.getStreamMaxVolume(AudioManager.STREAM_MUSIC); float volume = (float) streamVolume / (float) streamMaximum; int playingSound = soundPool.play(id, volume, volume, 0, 0, 1f); //should inject playingSound so it can be stopped/paused/resumed? }
From source file:com.nbplus.vbroadlauncher.RealtimeBroadcastActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); overridePendingTransition(R.anim.fade_in, R.anim.fade_out); acquireCpuWakeLock();/*from w ww . j a v a 2 s . c om*/ KeyguardManager km = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE); km.inKeyguardRestrictedInputMode(); if (km.inKeyguardRestrictedInputMode()) { Log.i(TAG, " ??"); isKeyguardRestrictedInputMode = true; } else { Log.i(TAG, " ??"); } mLastNetworkStatus = NetworkUtils.isConnected(this); Intent intent = getIntent(); if (intent == null || !PushConstants.ACTION_PUSH_MESSAGE_RECEIVED.equals(intent.getAction())) { Log.d(TAG, "empty or none broadcast intent value ..."); finishActivity(); return; } mBroadcastData = intent.getParcelableExtra(Constants.EXTRA_BROADCAST_PAYLOAD_DATA); if (mBroadcastData == null) { Log.d(TAG, ">> payload data is null"); finishActivity(); return; } mBroadcastPayloadIdx = intent.getLongExtra(Constants.EXTRA_BROADCAST_PAYLOAD_INDEX, -1); Log.d(TAG, ">> onCreate() mBroadcastPayloadIdx= " + mBroadcastPayloadIdx); // ? ms ? ?? ? ? ? ???? // broadcast ? . // ?? ?? ??. Intent i = new Intent(this, RealtimeBroadcastActivity.class); i.setAction(intent.getAction()); i.putExtra(Constants.EXTRA_BROADCAST_PAYLOAD_DATA, mBroadcastData); i.putExtra(Constants.EXTRA_BROADCAST_PAYLOAD_INDEX, mBroadcastPayloadIdx); LocalBroadcastManager.getInstance(this).sendBroadcast(i); IntentFilter filter = new IntentFilter(); filter.addAction(PushConstants.ACTION_PUSH_MESSAGE_RECEIVED); filter.addAction(Constants.ACTION_BROWSER_ACTIVITY_CLOSE); LocalBroadcastManager.getInstance(this).registerReceiver(mBroadcastReceiver, filter); IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION); registerReceiver(mBroadcastReceiver, intentFilter); hideSystemUI(); /* final Window win = getWindow(); win.setFlags( WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED | WindowManager.LayoutParams.FLAG_FULLSCREEN | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD, WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED | WindowManager.LayoutParams.FLAG_FULLSCREEN | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD); win.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON); */ if (Constants.PUSH_PAYLOAD_TYPE_TEXT_BROADCAST.equals(mBroadcastData.getServiceType())) { setContentView(R.layout.fragment_text_broadcast); } else { setContentView(R.layout.fragment_audio_broadcast); } getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD); if (Constants.PUSH_PAYLOAD_TYPE_TEXT_BROADCAST.equals(mBroadcastData.getServiceType())) { mcheckText2SpeechLister = this; // ? mTextView = (TextView) findViewById(R.id.broadcast_text); mTextView.setText(mBroadcastData.getMessage()); mTextView.setVerticalScrollBarEnabled(true); mTextView.setHorizontalScrollBarEnabled(false); mTextView.setMovementMethod(new ScrollingMovementMethod()); mHandler.sendEmptyMessageDelayed(HANDLER_MESSAGE_SETUP_CURRENT_PLAYING, 800); Log.d(TAG, "text broadcast = " + mBroadcastData.getMessage()); mText2SpeechHandler = new TextToSpeechHandler(this, this); checkText2SpeechAvailable(); mIsTTS = true; } else { // , ?? mWebView = (WebView) findViewById(R.id.webview); mWebViewClient = new RealtimeBroadcastWebViewClient(this, mWebView, this); mWebViewClient.setBackgroundTransparent(); String url = mBroadcastData.getMessage(); if (url.indexOf("?") > 0) { if (!url.contains("UUID=")) { url += ("&UUID=" + LauncherSettings.getInstance(this).getDeviceID()); } if (!url.contains("APPID=")) { url += ("&APPID=" + getApplicationContext().getPackageName()); } } else { if (!url.contains("UUID=")) { url += ("?UUID=" + LauncherSettings.getInstance(this).getDeviceID()); } if (!url.contains("APPID=")) { if (!url.contains("UUID=")) { url += ("?APPID=" + getApplicationContext().getPackageName()); } else { url += ("&APPID=" + getApplicationContext().getPackageName()); } } } mWebViewClient.loadUrl(url); mIsTTS = false; } AudioManager audio = (AudioManager) getSystemService(Context.AUDIO_SERVICE); mStreamMusicVolume = audio.getStreamVolume(AudioManager.STREAM_MUSIC); audio.setStreamVolume(AudioManager.STREAM_MUSIC, audio.getStreamMaxVolume(AudioManager.STREAM_MUSIC), AudioManager.FLAG_PLAY_SOUND); if (Constants.OPEN_BETA_PHONE && LauncherSettings.getInstance(this).isSmartPhone()) { StateListener phoneStateListener = new StateListener(); TelephonyManager telephonyManager = (TelephonyManager) getSystemService(TELEPHONY_SERVICE); telephonyManager.listen(phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE); } }
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); }/* ww w . j ava 2 s . c om*/ 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: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 ww . ja va 2s. co m*/ } 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
/** * Initialize the audio volume./*from w w w. ja v a 2 s . c om*/ */ private void initMediaPlayerVolume() { AudioManager audioManager = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE); // use the ringing volume to initialize the playing volume // it does not make sense to ring louder int maxVol = audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC); int minValue = firstCallAlert ? FIRST_PERCENT_VOLUME : DEFAULT_PERCENT_VOLUME; int ratio = (audioManager.getStreamVolume(AudioManager.STREAM_MUSIC) * 100) / maxVol; firstCallAlert = false; // ensure there is a minimum audio level // some users could complain they did not hear their device was ringing. if (ratio < minValue) { setMediaPlayerVolume(minValue); } else { setMediaPlayerVolume(ratio); } }
From source file:net.sourceforge.servestream.activity.MediaPlayerActivity.java
private synchronized void updateVolumeBar() { AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); int curVolume = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC); int maxVolume = audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC); if (mVolume != null) { mVolume.setProgress(curVolume);/* www . j av a 2 s. co m*/ mVolume.setMax(maxVolume); } }
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 w w w .ja va 2 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: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 ww w . ja v a 2 s .c om }