How to set the mediaplayer volume programmatically. I use it for alarm notification. Any help is highly appreciated and thanks in advance.
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How can I create this custom Bottom Navigation on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
Code:
Output
The below code sets the volume to the maximum level (getStreamMaxVolume()).
Using AudioManager you can control the volume of media player.
also from MediaPlayer (But I didn't try that)
Since: API Level 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.
Parameters
leftVolume left volume scalar
rightVolume right volume scalar
Try This
To Hide Volume Controll UI:
For Volume UP
for Volume Down
Read this page right here. It explains very well. Basically, unless your app is a replacement alarm clock, you need to make the following call in the "onCreate()" function:
In this way you can create the volume of your app using the hardware buttons.