0

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

Community
  • 1
  • 1
fralbo
  • 2,534
  • 4
  • 41
  • 73
  • that part `implements MediaController.MediaPlayerControl` gets it working... – njzk2 Sep 08 '14 at 15:23
  • I'm sorry but I don't understand what it's suppose to change to setMediaPlayer(mPlayMediaService);. The error is still the same. – fralbo Sep 08 '14 at 15:55
  • you call `setMediaPlayer(this);`. Unless `this` is an instance of a class that `implements MediaController.MediaPlayerControl`, this will produce this error. – njzk2 Sep 08 '14 at 16:01
  • ok, and I suppose that I'll have to use the MediaplayerControl methods to control the service? I tried but I cannot get the controller displayed... I'm going to investigate... Thks – fralbo Sep 08 '14 at 17:10
  • @caBBAlainB any updates? – Daniel Gomez Rico Oct 27 '15 at 21:11
  • 1
    @danielgomezrico unfortunately not, I gave it up as it wasn't a priority for me. I use my own buttons. – fralbo Oct 27 '15 at 21:40

0 Answers0