How to set android MediaPlayer volume according to ringtone volume? -


how can set mediaplayer sound volume according ringtone volume?

i did method, doesn't work:

        mediaplayer player = mediaplayer.create(myactivity.this, r.raw.sound);         audiomanager audio = (audiomanager) getsystemservice(context.audio_service);         int currentvolume = audio.getstreamvolume(audiomanager.ringer_mode_normal);          player.setvolume(currentvolume, currentvolume); 

instead of adjusting volume, should use setaudiostreamtype() set audio stream want play audio on - automatically uses volume of selected stream. example, if want audio play @ same volume notification would, use audiomanager.stream_notification:

mediaplayer.setaudiostreamtype(audiomanager.stream_notification); 

Comments

Popular posts from this blog

c - How to retrieve a variable from the Apache configuration inside the module? -

c# - Constructor arguments cannot be passed for interface mocks -

python - malformed header from script index.py Bad header -