修改Activity響應音量修飾鍵修改的音頻流

來源:互聯網
上載者:User

轉自:http://rainhomepage.appspot.com/2010/05/hardware-volume-controls-audio-stream-setvolumecontrolstream

當開發多媒體應用或者遊戲應用的時候,需要使用音量修飾鍵來設定程式的音量大小。在Android系統中有多中音頻流,通過Activity中的函數 setVolumeControlStream(int streamType)可以設定該Activity中音量修飾鍵控制的音頻流,一般在onCreate函數中設定。

Android中有如 下幾種音頻流:

  • AudioManager.STREAM_MUSIC  /** The audio stream for music playback */
  • AudioManager.STREAM_RING /** The audio stream for the phone ring */
  • AudioManager.STREAM_ALARM  /** The audio stream for alarms */
  • AudioManager.STREAM_NOTIFICATION /** The audio stream for notifications */
  • AudioManager.STREAM_SYSTEM  /** The audio stream for system sounds */
  • AudioManager.STREAM_VOICECALL /** The audio stream for phone calls */

setVolumeControlStream函數描述:

void android.app.Activity .setVolumeControlStream(int streamType)

Suggests an audio stream whose volume should be changed by the hardware volume controls.

The suggested audio stream will be tied to the window of this Activity. If the Activity is switched, the stream set here is no longer the suggested stream. The client does not need to save and restore the old suggested stream value in onPause and onResume.

Parameters:
streamType The type of the audio stream whose volume should be changed by the hardware volume controls. It is not guaranteed that the hardware volume controls will always change this stream's volume (for example, if a call is in progress, its stream's volume may be changed instead). To reset back to the default, use  AudioManager.USE_DEFAULT_STREAM_TYPE .

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.