Android音量擷取——常備混淆的東西

來源:互聯網
上載者:User

今天在項目中遇到一個需求,利用seekbar來實現控制音量的大小。


本以為一個很簡單的事情(確實是一個很簡單的事情),但是剛開始卻實現不了我想要的效果。經過一番修改、尋找終於解決了。而在解決過程中,也發現了自己對android一些地方認識的不足之處。


那麼,就事論事。今天暫且說一下音量這一塊吧。


android系統中的聲音有系統音量、通話音量、鈴聲音量、音樂音量、提示聲音音量(我之前一直以為android中就只有一種音量:系統音量(自學的不全面。。。。。))。


那麼下面就逐次介紹一下這幾種音量的擷取方法把


擷取這幾種音量都需要一個共同的控制音量的類AudioManager (具體幹嘛的自己百度 一下就可以)


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


int max;//最大音量

int current;//當前音量


//系統音量

max = mAudioManager.getStreamMaxVolume( AudioManager.STREAM_SYSTEM );

current = mAudioManager.getStreamVolume( AudioManager.STREAM_SYSTEM );


//通話音量

int max = am.getStreamMaxVolume( AudioManager.STREAM_VOICE_CALL );

int current = am.getStreamVolume( AudioManager.STREAM_VOICE_CALL );


//鈴聲音量

max = mAudioManager.getStreamMaxVolume( AudioManager.STREAM_RING );

current = mAudioManager.getStreamVolume( AudioManager.STREAM_RING );


//音樂音量

max = mAudioManager.getStreamMaxVolume( AudioManager.STREAM_MUSIC );

current = mAudioManager.getStreamVolume( AudioManager.STREAM_MUSIC );


//提示聲音音量

max = am.getStreamMaxVolume( AudioManager.STREAM_ALARM );

current = sm.getStreamVolume( AudioManager.STREAM_ALARM );

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.