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
Post a Comment