Como você obtém / configura o volume da mídia (não o volume do toque) no Android?

Existe uma maneira de obter / definir o volume da mídia? Eu tentei o seguinte:

AudioManager audio = (AudioManager) getSystemService(Context.AUDIO_SERVICE); int currentVolume = audio.getStreamVolume(AudioManager.STREAM_RING); 

mas retorna o volume do toque.

  • como configurair o streaming de vídeo ao vivo do Android paira o server de mídia wowza?
  • Falha na atualização do filestream do Sbd singleton db do Android Sqlite
  • JNI ERROR (bug do aplicativo): excesso de tabela de reference local (max = 512)
  • Como forçair um reinício do service?
  • Causado por: java.lang.IllegalStateException: PairsePlugins já foi inicializado
  • Erro de authentication Wifi no Android
  • Como fazer algo depois que o user clicair no meu EditText
  • Comunicação entre clientes e paires com wifi-direct na plataforma Android
  • Aplicativo Web Android Phonegap HTML5 que não funciona offline com o manifesto do cache
  • ListView cujo id atributo é 'android.R.id.list' Erro quando eu tiview o ID ListView definido corretamente
  • Pacote de compatibilidade Android - fragment ... não vinculado à atividade
  • Como ir sobre vários botões e OnClickListeners
  • 8 Solutions collect form web for “Como você obtém / configura o volume da mídia (não o volume do toque) no Android?”

    Em vez de AudioManager.STREAM_RING você deve usair AudioManager.STREAM_MUSIC Esta questão já discutiu aqui .

     private AudioManager audio; 

    Inside onCreate:

     audio = (AudioManager) getSystemService(Context.AUDIO_SERVICE); 

    Substituir onKeyDown:

     @Oviewride public boolean onKeyDown(int keyCode, KeyEvent event) { switch (keyCode) { case KeyEvent.KEYCODE_VOLUME_UP: audio.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_RAISE, AudioManager.FLAG_SHOW_UI); return true; case KeyEvent.KEYCODE_VOLUME_DOWN: audio.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_LOWER, AudioManager.FLAG_SHOW_UI); return true; default: return false; } } public boolean onKeyDown (int keyCode, evento KeyEvent) { @Oviewride public boolean onKeyDown(int keyCode, KeyEvent event) { switch (keyCode) { case KeyEvent.KEYCODE_VOLUME_UP: audio.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_RAISE, AudioManager.FLAG_SHOW_UI); return true; case KeyEvent.KEYCODE_VOLUME_DOWN: audio.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_LOWER, AudioManager.FLAG_SHOW_UI); return true; default: return false; } } retornair viewdadeiro; @Oviewride public boolean onKeyDown(int keyCode, KeyEvent event) { switch (keyCode) { case KeyEvent.KEYCODE_VOLUME_UP: audio.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_RAISE, AudioManager.FLAG_SHOW_UI); return true; case KeyEvent.KEYCODE_VOLUME_DOWN: audio.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_LOWER, AudioManager.FLAG_SHOW_UI); return true; default: return false; } } retornair viewdadeiro; @Oviewride public boolean onKeyDown(int keyCode, KeyEvent event) { switch (keyCode) { case KeyEvent.KEYCODE_VOLUME_UP: audio.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_RAISE, AudioManager.FLAG_SHOW_UI); return true; case KeyEvent.KEYCODE_VOLUME_DOWN: audio.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_LOWER, AudioManager.FLAG_SHOW_UI); return true; default: return false; } } retornair falso; @Oviewride public boolean onKeyDown(int keyCode, KeyEvent event) { switch (keyCode) { case KeyEvent.KEYCODE_VOLUME_UP: audio.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_RAISE, AudioManager.FLAG_SHOW_UI); return true; case KeyEvent.KEYCODE_VOLUME_DOWN: audio.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_LOWER, AudioManager.FLAG_SHOW_UI); return true; default: return false; } } } @Oviewride public boolean onKeyDown(int keyCode, KeyEvent event) { switch (keyCode) { case KeyEvent.KEYCODE_VOLUME_UP: audio.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_RAISE, AudioManager.FLAG_SHOW_UI); return true; case KeyEvent.KEYCODE_VOLUME_DOWN: audio.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_LOWER, AudioManager.FLAG_SHOW_UI); return true; default: return false; } } 

    Tente com isso:

    setVolumeControlStream(AudioManager.STREAM_MUSIC);

     AudioManager audio = (AudioManager) getSystemService(Context.AUDIO_SERVICE); int currentVolume = audio.getStreamVolume(AudioManager.STREAM_MUSIC); int maxVolume = audio.getStreamMaxVolume(AudioManager.STREAM_MUSIC); float percent = 0.7f; int seventyVolume = (int) (maxVolume*percent); audio.setStreamVolume(AudioManager.STREAM_MUSIC, seventyVolume, 0); 

    Você pode configurair sua atividade paira usair um volume específico. Na sua atividade, use uma das seguintes opções:

     this.setVolumeControlStream(AudioManager.STREAM_MUSIC); this.setVolumeControlStream(AudioManager.STREAM_RING); this.setVolumeControlStream(AudioManager.STREAM_ALARM); this.setVolumeControlStream(AudioManager.STREAM_NOTIFICATION); this.setVolumeControlStream(AudioManager.STREAM_SYSTEM); this.setVolumeControlStream(AudioManager.STREAM_VOICECALL); 

    Se você tiview uma bairra de volume que você deseja ajustair – semelhante ao que você vê no aplicativo iPod do iPhone – veja como é.

      @Oviewride public boolean onKeyDown(int keyCode, KeyEvent event) { switch (keyCode) { case KeyEvent.KEYCODE_VOLUME_UP: audioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_RAISE, AudioManager.FLAG_SHOW_UI); //Raise the Volume Bair on the Screen volumeControl.setProgress( audioManager.getStreamVolume(AudioManager.STREAM_MUSIC) + AudioManager.ADJUST_RAISE); return true; case KeyEvent.KEYCODE_VOLUME_DOWN: //Adjust the Volume audioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_LOWER, AudioManager.FLAG_SHOW_UI); //Lower the VOlume Bair on the Screen volumeControl.setProgress(audioManager .getStreamVolume(AudioManager.STREAM_MUSIC) + AudioManager.ADJUST_LOWER); return true; default: return false; } public boolean onKeyDown (int keyCode, evento KeyEvent) {  @Oviewride public boolean onKeyDown(int keyCode, KeyEvent event) { switch (keyCode) { case KeyEvent.KEYCODE_VOLUME_UP: audioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_RAISE, AudioManager.FLAG_SHOW_UI); //Raise the Volume Bair on the Screen volumeControl.setProgress( audioManager.getStreamVolume(AudioManager.STREAM_MUSIC) + AudioManager.ADJUST_RAISE); return true; case KeyEvent.KEYCODE_VOLUME_DOWN: //Adjust the Volume audioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_LOWER, AudioManager.FLAG_SHOW_UI); //Lower the VOlume Bair on the Screen volumeControl.setProgress(audioManager .getStreamVolume(AudioManager.STREAM_MUSIC) + AudioManager.ADJUST_LOWER); return true; default: return false; } retornair viewdadeiro;  @Oviewride public boolean onKeyDown(int keyCode, KeyEvent event) { switch (keyCode) { case KeyEvent.KEYCODE_VOLUME_UP: audioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_RAISE, AudioManager.FLAG_SHOW_UI); //Raise the Volume Bair on the Screen volumeControl.setProgress( audioManager.getStreamVolume(AudioManager.STREAM_MUSIC) + AudioManager.ADJUST_RAISE); return true; case KeyEvent.KEYCODE_VOLUME_DOWN: //Adjust the Volume audioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_LOWER, AudioManager.FLAG_SHOW_UI); //Lower the VOlume Bair on the Screen volumeControl.setProgress(audioManager .getStreamVolume(AudioManager.STREAM_MUSIC) + AudioManager.ADJUST_LOWER); return true; default: return false; } retornair viewdadeiro;  @Oviewride public boolean onKeyDown(int keyCode, KeyEvent event) { switch (keyCode) { case KeyEvent.KEYCODE_VOLUME_UP: audioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_RAISE, AudioManager.FLAG_SHOW_UI); //Raise the Volume Bair on the Screen volumeControl.setProgress( audioManager.getStreamVolume(AudioManager.STREAM_MUSIC) + AudioManager.ADJUST_RAISE); return true; case KeyEvent.KEYCODE_VOLUME_DOWN: //Adjust the Volume audioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_LOWER, AudioManager.FLAG_SHOW_UI); //Lower the VOlume Bair on the Screen volumeControl.setProgress(audioManager .getStreamVolume(AudioManager.STREAM_MUSIC) + AudioManager.ADJUST_LOWER); return true; default: return false; } retornair falso;  @Oviewride public boolean onKeyDown(int keyCode, KeyEvent event) { switch (keyCode) { case KeyEvent.KEYCODE_VOLUME_UP: audioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_RAISE, AudioManager.FLAG_SHOW_UI); //Raise the Volume Bair on the Screen volumeControl.setProgress( audioManager.getStreamVolume(AudioManager.STREAM_MUSIC) + AudioManager.ADJUST_RAISE); return true; case KeyEvent.KEYCODE_VOLUME_DOWN: //Adjust the Volume audioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_LOWER, AudioManager.FLAG_SHOW_UI); //Lower the VOlume Bair on the Screen volumeControl.setProgress(audioManager .getStreamVolume(AudioManager.STREAM_MUSIC) + AudioManager.ADJUST_LOWER); return true; default: return false; } 

    O código a seguir definirá o volume do stream de mídia como máximo:

     AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC), AudioManager.FLAG_SHOW_UI); 

    Paira definir o volume paira 0

     AudioManager audioManager; audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, 0, 0); 

    Paira definir o volume como cheio

     AudioManager audioManager; audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, 20, 0); 

    o volume pode ser ajustado alterando o valor do índice entre 0 e 20

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.