I have an application based on fragments where the MediaPlayer is implemented as a service. I'd like to use the mediaController. I'm in the same case as explained here (Android: How to use mediaController in service class?). I think.
My application setup the mediacontroller like that: private ServiceConnection mConnection = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName className, IBinder service) {
// We've bound to LocalService, cast the IBinder and get LocalService instance
LocalBinder binder = (LocalBinder) service;
mPlayMediaService = binder.getService();
AudioManager am = (AudioManager) getActivity().getSystemService(Context.AUDIO_SERVICE);
ComponentName component = new ComponentName(getActivity(), Fragment_playMedias.class);
am.registerMediaButtonEventReceiver(component);
site.setMediaController(new MediaController(getActivity(),false));
site.getMediaController().setAnchorView(getView().findViewById(R.id.relativeLayoutAudioControl));
site.getMediaController().setMediaPlayer(this);
site.getMediaController().setEnabled(true);
site.getMediaController().show();
mBound = true;
}
@Override
public void onServiceDisconnected(ComponentName arg0) {
mBound = false;
}
};
I don't know it the API changed recently but the it's not possible to setMediaPlayer() with the reference returned by binder.getService().
Eclipse says: The method setMediaPlayer(MediaController.MediaPlayerControl) in the type MediaController is not applicable for the arguments (new ServiceConnection(){})
So I wonder how the author get it working!?!
Any idea?
Regards, Alain