Skip to content
Snippets Groups Projects
Commit 3a615df1 authored by himta ram's avatar himta ram
Browse files

FM: Query and apply STREAM_MUSIC volume

    when output device routing changes.

   -when ever Bluetooth device connect/disconnect
   query for STREAM_MUSIC volume and apply to fm volume.

Change-Id: I0a1cb47f7469439b94ac4b87f3c7cf58a0bbd3b1
parent ccab50c9
No related branches found
No related tags found
No related merge requests found
......@@ -422,6 +422,16 @@ public class FMRadioService extends Service
return true;
}
private void setCurrentFMVolume() {
if(isFmOn()) {
AudioManager maudioManager =
(AudioManager) getSystemService(Context.AUDIO_SERVICE);
int mCurrentVolumeIndex =
maudioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
setFMVolume(mCurrentVolumeIndex);
}
}
/**
* Registers an intent to listen for ACTION_MEDIA_UNMOUNTED notifications.
* The intent will call closeExternalStorageFiles() if the external media
......@@ -591,8 +601,19 @@ public class FMRadioService extends Service
intent.getIntExtra(AudioManager.EXTRA_VOLUME_STREAM_VALUE, -1);
setFMVolume(mCurrentVolumeIndex);
}
}
} else if (action.equals(BluetoothA2dp.ACTION_ACTIVE_DEVICE_CHANGED)) {
mHandler.removeCallbacks(mFmVolumeHandler);
mHandler.post(mFmVolumeHandler);
} else if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED)) {
int state =
intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR);
Log.d(LOGTAG, "ACTION_STATE_CHANGED state :"+ state);
if (state == BluetoothAdapter.STATE_OFF) {
mHandler.removeCallbacks(mFmVolumeHandler);
mHandler.post(mFmVolumeHandler);
}
}
}
};
AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
......@@ -602,6 +623,8 @@ public class FMRadioService extends Service
iFilter.addAction("HDMI_CONNECTED");
iFilter.addAction(Intent.ACTION_SHUTDOWN);
iFilter.addAction(AudioManager.VOLUME_CHANGED_ACTION);
iFilter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);
iFilter.addAction(BluetoothA2dp.ACTION_ACTIVE_DEVICE_CHANGED);
iFilter.addCategory(Intent.CATEGORY_DEFAULT);
registerReceiver(mHeadsetReceiver, iFilter);
}
......@@ -705,7 +728,17 @@ public class FMRadioService extends Service
}
}
final Runnable mFmVolumeHandler = new Runnable() {
public void run() {
try {
Thread.sleep(1000);
} catch (Exception ex) {
Log.d( LOGTAG, "RunningThread InterruptedException");
return;
}
setCurrentFMVolume();
}
};
final Runnable mHeadsetPluginHandler = new Runnable() {
public void run() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment