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++ - llvm function pass ReplaceInstWithInst malloc -

java.lang.NoClassDefFoundError When Creating New Android Project -

Decoding a Python 2 `tempfile` with python-future -