Thursday, 15 January 2015

android - How to mute and unmute it on the onPause and onResume -



android - How to mute and unmute it on the onPause and onResume -

i'm having problem when set sound mute on onpause() , in onresume() seek unmute without success.

code:

protected void onpause() { super.onpause(); log.d(tag, "onpause"); setstreammute(true); } protected void onresume() { super.onresume(); log.d(tag, "onresume"); setstreammute(false); } public void setstreammute (boolean state){ log.d(tag,"setmute: "+state); myaudiomanager = (audiomanager)getsystemservice(context.audio_service); myaudiomanager.setstreammute(audiomanager.stream_music, state); }

any help welcome, thanks.

mediaplayer oursong; int length; // save lastly seconds music has paused

in oncreate

oursong = mediaplayer.create(youractivity.this, yoursong); oursong.setlooping(true); oursong.start();

in pause function

oursong.pause(); length = oursong.getcurrentposition();

in resume function

oursong.seekto(length); oursong.start(); note:

you should create folder row , yoursong has r.raw.yoursong

android audio onresume onpause mute

No comments:

Post a Comment