From 76b2c967bc15626b09410a4a8d54d59b8bd712dc Mon Sep 17 00:00:00 2001 From: Dhananjay Kumar <dhakumar@codeaurora.org> Date: Mon, 25 Jan 2016 20:30:17 +0530 Subject: [PATCH] Update mute API usage to fix pops and consistency Remove deprecated setStreamMute API and instead control volume of audio track. Since we are controlling mute/unmute state of FM audio track, we don't have to save/restore it for other audio applications. CRs-Fixed: 966690 Change-Id: I242c63c3edd988ed4b85e631b857d0696935cb76 --- fmapp2/src/com/caf/fmradio/FMRadioService.java | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/fmapp2/src/com/caf/fmradio/FMRadioService.java b/fmapp2/src/com/caf/fmradio/FMRadioService.java index e5471c9..188a068 100644 --- a/fmapp2/src/com/caf/fmradio/FMRadioService.java +++ b/fmapp2/src/com/caf/fmradio/FMRadioService.java @@ -283,10 +283,6 @@ public class FMRadioService extends Service cancelAlarms(); //release the audio focus listener AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); - if (isMuted()) { - mMuted = false; - audioManager.setStreamMute(AudioManager.STREAM_MUSIC,false); - } audioManager.abandonAudioFocus(mAudioFocusListener); /* Remove the Screen On/off listener */ if (mScreenOnOffReceiver != null) { @@ -356,6 +352,8 @@ public class FMRadioService extends Service AUDIO_SAMPLE_RATE, AUDIO_CHANNEL_CONFIG, AUDIO_ENCODING_FORMAT, FM_RECORD_BUF_SIZE, AudioTrack.MODE_STREAM); + if (mMuted) + mAudioTrack.setVolume(0.0f); } private synchronized void startRecordSink() { @@ -1530,8 +1528,6 @@ public class FMRadioService extends Service mSpeakerDisableHandler.postDelayed(mSpeakerDisableTask, 0); } if (true == mPlaybackInProgress) { - if(mMuted) - unMute(); stopFM(); } if (mSpeakerPhoneOn) { @@ -2145,7 +2141,6 @@ public class FMRadioService extends Service if(audioManager != null) { Log.d(LOGTAG, "audioManager.setFmRadioOn = false \n" ); - unMute(); stopFM(); //audioManager.setParameters("FMRadioOn=false"); Log.d(LOGTAG, "audioManager.setFmRadioOn false done \n" ); @@ -2396,7 +2391,9 @@ public class FMRadioService extends Service if (audioManager != null) { mMuted = true; - audioManager.setStreamMute(AudioManager.STREAM_MUSIC,true); + audioManager.setParameters("fm_mute=1"); + if (mAudioTrack != null) + mAudioTrack.setVolume(0.0f); } return bCommandSent; } @@ -2416,7 +2413,9 @@ public class FMRadioService extends Service if (audioManager != null) { mMuted = false; - audioManager.setStreamMute(AudioManager.STREAM_MUSIC,false); + audioManager.setParameters("fm_mute=0"); + if (mAudioTrack != null) + mAudioTrack.setVolume(1.0f); if (mResumeAfterCall) { //We are unmuting FM in a voice call. Need to enable FM audio routing. -- GitLab