public void bindAudioService(Context context) {
Log.i("DAHYE","bindAudioService");
if (context == null) {
Log.w(TAG, "bindAudioService() with null Context. Ooops" );
return;
}
context = context.getApplicationContext();
if (!mIsBound) {
Log.i("DAHYE","intent AudioService befroe");
Intent service = new Intent(context, AudioService.class);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
final boolean enableHS = prefs.getBoolean("enable_headset_detection", true);
// Setup audio service connection , 오디오 서비스 연결
mAudioServiceConnection = new ServiceConnection() {
@Override
public void onServiceDisconnected(ComponentName name) {
Log.d(TAG, "Service Disconnected");
mAudioServiceBinder = null;
mIsBound = false;
}
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
Log.d(TAG, "onServiceConnected "+mIsBound);
if (!mIsBound) // Can happen if unbind is called quickly before this callback
return;
Log.d(TAG, "Service Connected");
mAudioServiceBinder = IAudioService.Stub.asInterface(service);
// Register controller to the service
try {
mAudioServiceBinder.addAudioCallback(mCallback);
mAudioServiceBinder.detectHeadset(enableHS);
} catch (RemoteException e) {
Log.e(TAG, "remote procedure call failed: addAudioCallback()");
}
updateAudioPlayer();
}
};
context.startService(service);
mIsBound = context.bindService(service, mAudioServiceConnection, 0);
Log.d("mLog", "bind : " + mIsBound);
} else {
// Register controller to the service
try {
if (mAudioServiceBinder != null)
mAudioServiceBinder.addAudioCallback(mCallback);
} catch (RemoteException e) {
Log.e(TAG, "remote procedure call failed: addAudioCallback()");
}
}
}
오디오 서비스 연결하는 부분에서 serviceConnection안으로 들어가지 않아요ㅠㅠ 그래서 servicconnected도 당연히 안되구요ㅠㅠ 오픈소스 참고중이라 뭐가뭔지 어렵기만 합니다ㅠㅠ