List of usage examples for android.media AudioManager getStreamVolume
public int getStreamVolume(int streamType)
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.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); }/*from ww 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.hhunj.hhudata.ForegroundService.java
private MediaPlayer ring() throws Exception, IOException { Uri alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); MediaPlayer player = new MediaPlayer(); player.setDataSource(this, alert); final AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); if (audioManager.getStreamVolume(AudioManager.STREAM_NOTIFICATION) != 0) { player.setAudioStreamType(AudioManager.STREAM_NOTIFICATION); player.setLooping(true);//from w w w. j a va 2 s. co m player.prepare(); player.start(); } return player; }
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 www .ja va2s .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:edu.missouri.bas.service.SensorService.java
public void playSound(int sound, float fSpeed) { AudioManager mgr = (AudioManager) getSystemService(Context.AUDIO_SERVICE); float streamVolumeCurrent = mgr.getStreamVolume(AudioManager.STREAM_MUSIC); float volume = streamVolumeCurrent; mSoundPool.play(soundsMap.get(sound), volume, volume, 1, 0, fSpeed); }
From source file:org.sipdroid.sipua.ui.Receiver.java
public static void onState(int state, String caller) { if (ccCall == null) { ccCall = new Call(); ccConn = new Connection(); ccCall.setConn(ccConn);/*from www .ja v a2s.c om*/ ccConn.setCall(ccCall); } if (call_state != state) { if (state != UserAgent.UA_STATE_IDLE) call_end_reason = -1; call_state = state; switch (call_state) { case UserAgent.UA_STATE_INCOMING_CALL: enable_wifi(true); RtpStreamReceiver.good = RtpStreamReceiver.lost = RtpStreamReceiver.loss = RtpStreamReceiver.late = 0; RtpStreamReceiver.speakermode = speakermode(); bluetooth = -1; String text = caller.toString(); if (text.indexOf("<sip:") >= 0 && text.indexOf("@") >= 0) text = text.substring(text.indexOf("<sip:") + 5, text.indexOf("@")); String text2 = caller.toString(); if (text2.indexOf("\"") >= 0) text2 = text2.substring(text2.indexOf("\"") + 1, text2.lastIndexOf("\"")); broadcastCallStateChanged("RINGING", caller); mContext.sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)); ccCall.setState(Call.State.INCOMING); ccConn.setUserData(null); ccConn.setAddress(text, text2); ccConn.setIncoming(true); ccConn.date = System.currentTimeMillis(); ccCall.base = 0; AudioManager am = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE); int rm = am.getRingerMode(); int vs = am.getVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER); KeyguardManager mKeyguardManager = (KeyguardManager) mContext .getSystemService(Context.KEYGUARD_SERVICE); if (v == null) v = (Vibrator) mContext.getSystemService(Context.VIBRATOR_SERVICE); if ((pstn_state == null || pstn_state.equals("IDLE")) && PreferenceManager.getDefaultSharedPreferences(mContext).getBoolean( org.sipdroid.sipua.ui.Settings.PREF_AUTO_ON, org.sipdroid.sipua.ui.Settings.DEFAULT_AUTO_ON) && !mKeyguardManager.inKeyguardRestrictedInputMode()) v.vibrate(vibratePattern, 1); else { if ((pstn_state == null || pstn_state.equals("IDLE")) && (rm == AudioManager.RINGER_MODE_VIBRATE || (rm == AudioManager.RINGER_MODE_NORMAL && vs == AudioManager.VIBRATE_SETTING_ON))) v.vibrate(vibratePattern, 1); if (am.getStreamVolume(AudioManager.STREAM_RING) > 0) { String sUriSipRingtone = PreferenceManager.getDefaultSharedPreferences(mContext).getString( org.sipdroid.sipua.ui.Settings.PREF_SIPRINGTONE, Settings.System.DEFAULT_RINGTONE_URI.toString()); if (!TextUtils.isEmpty(sUriSipRingtone)) { oRingtone = RingtoneManager.getRingtone(mContext, Uri.parse(sUriSipRingtone)); if (oRingtone != null) oRingtone.play(); } } } moveTop(); if (wl == null) { PowerManager pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE); wl = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "Sipdroid.onState"); } wl.acquire(); Checkin.checkin(true); break; case UserAgent.UA_STATE_OUTGOING_CALL: RtpStreamReceiver.good = RtpStreamReceiver.lost = RtpStreamReceiver.loss = RtpStreamReceiver.late = 0; RtpStreamReceiver.speakermode = speakermode(); bluetooth = -1; onText(MISSED_CALL_NOTIFICATION, null, 0, 0); engine(mContext).register(); broadcastCallStateChanged("OFFHOOK", caller); ccCall.setState(Call.State.DIALING); ccConn.setUserData(null); ccConn.setAddress(caller, caller); ccConn.setIncoming(false); ccConn.date = System.currentTimeMillis(); ccCall.base = 0; moveTop(); Checkin.checkin(true); break; case UserAgent.UA_STATE_IDLE: broadcastCallStateChanged("IDLE", null); onText(CALL_NOTIFICATION, null, 0, 0); ccCall.setState(Call.State.DISCONNECTED); if (listener_video != null) listener_video.onHangup(); stopRingtone(); if (wl != null && wl.isHeld()) wl.release(); mContext.startActivity(createIntent(InCallScreen.class)); ccConn.log(ccCall.base); ccConn.date = 0; engine(mContext).listen(); break; case UserAgent.UA_STATE_INCALL: broadcastCallStateChanged("OFFHOOK", null); if (ccCall.base == 0) { ccCall.base = SystemClock.elapsedRealtime(); } progress(); ccCall.setState(Call.State.ACTIVE); stopRingtone(); if (wl != null && wl.isHeld()) wl.release(); mContext.startActivity(createIntent(InCallScreen.class)); break; case UserAgent.UA_STATE_HOLD: onText(CALL_NOTIFICATION, mContext.getString(R.string.card_title_on_hold), android.R.drawable.stat_sys_phone_call_on_hold, ccCall.base); ccCall.setState(Call.State.HOLDING); if (InCallScreen.started && (pstn_state == null || !pstn_state.equals("RINGING"))) mContext.startActivity(createIntent(InCallScreen.class)); break; } pos(true); RtpStreamReceiver.ringback(false); } }
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);//from w w w .j a v a2 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(""); }// www. ja v a2s . 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 w w w . ja v a 2 s .c o m }
From source file:im.vector.activity.CallViewActivity.java
/** * Initialize the audio volume.//from w w w . j av a2 s. co m */ 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); } }