在Android的改变媒体音量? [英] Change Media volume in Android?

查看:793
本文介绍了在Android的改变媒体音量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以改变媒体音量?如何?我用这个至今:

Can I change the media volume? and how? I used this so far:

setVolumeControlStream(AudioManager.STREAM_MUSIC);

但有一个搜索栏,并想改变媒体音量,没有振铃的音量。

But have a seekbar and want to change the media volume, not ring volume.

所以有人可以告诉我怎么只是改变媒体音量的onCreate()和我修复搜索栏后。

So can someone show me how to just change the media volume at onCreate() and I fix the seekbar later.

推荐答案

正确的方法使用的是<一href="http://developer.android.com/reference/android/media/AudioManager.html#setStreamVolume">setStreamVolume在 AudioManager 。它可能看起来像这样

The right method to use would be setStreamVolume on your AudioManager. It could looks like this

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

audioManager.setStreamVolume(AudioManager.STREAM_MUSIC,
                             [int value],
                             [if desired a flag]);

这是例子使用的标志是设置音量,使用户可以听到结果时,得到的提示音。的标志,这将是 AudioManager.FLAG_PLAY_SOUND

An example use of the flag is to get the beep when setting the volume so the user can hear the outcome. The flag for that would be AudioManager.FLAG_PLAY_SOUND.

您可以使用 AudioManager.FLAG_SHOW_UI 如果你不想播放声音,但显示的当前值敬酒。利用已获得的反馈寿。不要紧,如果是音频或视频。

You could use AudioManager.FLAG_SHOW_UI if you don't want to play a sound but display a toast with the current value. The use has to get a feedback tho. Doesn't matter if it is audible or visual.

要获取给定流,你只需要调用的最大有效值 getStreamMaxVolume() AudioManager 并获得一个整数回到从而重新presents ...好了体积最大的有效值。

To get the maximal valid value for the given stream you just call getStreamMaxVolume() on the AudioManager and get an integer back which represents ... well the maximal valid value for the volume.

这篇关于在Android的改变媒体音量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆