I am trying to play sound via media player on STREAM_SYSTEM
我正在流媒体播放器上播放声音
using
使用
mediaPlayer.setVolume(1.0f , 1.0f);
or
或
mediaPlayer.setVolume(0.90f , 0.90f);
But it is playing on vol as per Hardware volume controls in settings.
但它是在卷按硬件音量设置。
Basically this line has no effect.
这条线基本上没有影响。
I have added
我已经添加了
permissions "Modify..." as well in Manifest
But i saw links in * where this API works.
但是我在*上看到了这个API的链接。
I don't wanna go to API
我不想去API
AudioManager.setStreamVol()....
as it sets stream vol for all apps
因为它为所有的应用设置流vol
What is problem that this setVol API is not working??
这个setVol API不工作的问题是什么?
Can anybody give a link to working sample??
谁能给一个链接示例工作吗? ?
4 个解决方案
#1
5
I faced the same issue. I thought that if I use 0.5f as parameter, I could tell the difference. I tried 0.2f, still no difference. So I thought there was a problem indeed. I finally tried 0.02f just in case, and finally I had a lower volume.
我面临着同样的问题。我想如果我用0。5f作为参数,我就能分辨出不同。我试了0.2华氏度,仍然没有区别。所以我认为确实存在一个问题。我最后尝试了0。02f以防万一,最后我的体积变小了。
Sample:
示例:
replace your
取代你
mediaPlayer.setVolume(0.90f , 0.90f);
with
与
mediaPlayer.setVolume(0.09f , 0.09f);
#2
0
You must put the volume value between 0.0f and 1.0f. So 1.0f is 100% of the volume. Because of that your line has not effect.
您必须将卷值放在0.0f和1.0f之间。所以1。0f是体积的100%因为那你的台词没有效果。
#3
0
AudioManager audioManager;
int actualVolume;
audioManager = (AudioManager) getSystemService(AUDIO_SERVICE);
actualVolume = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, actualVolume + 1, AudioManager.FLAG_SHOW_UI);
The above code is taken from my working project, where it is used to increase the volume of the system (I used it for TV). You can use actualVolume - 1
to lower down the volume.
以上代码取自我的工作项目,用于增加系统的容量(我在TV中使用它)。你可以使用实际体积- 1来降低体积。
#4
-1
Using AudioManager you can control the volume of media player.
使用AudioManager你可以控制媒体播放器的音量。
AudioManager audioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, 20, 0);
also from MediaPlayer (But I didn't try that)
也来自MediaPlayer(但我没有尝试过)
public void setVolume (float leftVolume, float rightVolume)
Since: API Level 1:
自:API级别1:
Sets the volume on this player. This API is recommended for balancing the output of audio streams within an application. Unless you are writing an application to control user settings, this API should be used in preference to setStreamVolume(int, int, int) which sets the volume of ALL streams of a particular type. Note that the passed volume values are raw scalars. UI controls should be scaled logarithmically.
设置此播放器的音量。建议使用此API来平衡应用程序中音频流的输出。除非您正在编写一个用于控制用户设置的应用程序,否则这个API应该用于setStreamVolume(int, int, int),它设置了特定类型的所有流的卷。注意,传递的卷值是原始标量。UI控件的比例应该是对数的。
Parameters:
参数:
leftVolume left volume scalar
leftVolume左卷标量
rightVolume right volume scalar
rightVolume正确体积标量
#1
5
I faced the same issue. I thought that if I use 0.5f as parameter, I could tell the difference. I tried 0.2f, still no difference. So I thought there was a problem indeed. I finally tried 0.02f just in case, and finally I had a lower volume.
我面临着同样的问题。我想如果我用0。5f作为参数,我就能分辨出不同。我试了0.2华氏度,仍然没有区别。所以我认为确实存在一个问题。我最后尝试了0。02f以防万一,最后我的体积变小了。
Sample:
示例:
replace your
取代你
mediaPlayer.setVolume(0.90f , 0.90f);
with
与
mediaPlayer.setVolume(0.09f , 0.09f);
#2
0
You must put the volume value between 0.0f and 1.0f. So 1.0f is 100% of the volume. Because of that your line has not effect.
您必须将卷值放在0.0f和1.0f之间。所以1。0f是体积的100%因为那你的台词没有效果。
#3
0
AudioManager audioManager;
int actualVolume;
audioManager = (AudioManager) getSystemService(AUDIO_SERVICE);
actualVolume = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, actualVolume + 1, AudioManager.FLAG_SHOW_UI);
The above code is taken from my working project, where it is used to increase the volume of the system (I used it for TV). You can use actualVolume - 1
to lower down the volume.
以上代码取自我的工作项目,用于增加系统的容量(我在TV中使用它)。你可以使用实际体积- 1来降低体积。
#4
-1
Using AudioManager you can control the volume of media player.
使用AudioManager你可以控制媒体播放器的音量。
AudioManager audioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, 20, 0);
also from MediaPlayer (But I didn't try that)
也来自MediaPlayer(但我没有尝试过)
public void setVolume (float leftVolume, float rightVolume)
Since: API Level 1:
自:API级别1:
Sets the volume on this player. This API is recommended for balancing the output of audio streams within an application. Unless you are writing an application to control user settings, this API should be used in preference to setStreamVolume(int, int, int) which sets the volume of ALL streams of a particular type. Note that the passed volume values are raw scalars. UI controls should be scaled logarithmically.
设置此播放器的音量。建议使用此API来平衡应用程序中音频流的输出。除非您正在编写一个用于控制用户设置的应用程序,否则这个API应该用于setStreamVolume(int, int, int),它设置了特定类型的所有流的卷。注意,传递的卷值是原始标量。UI控件的比例应该是对数的。
Parameters:
参数:
leftVolume left volume scalar
leftVolume左卷标量
rightVolume right volume scalar
rightVolume正确体积标量