1

I need to make a Controller for my player app. With the help of it user would play, pause, choose next or previous song. But this controller isn't shown and I don't know why?

I have already done method for setting data for controller and class for this controller.

Here's the code of the method:

private void setController(){
    controller = new MusicController(this);
    controller.setPrevNextListeners(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            playNext();
        }
    }, new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            playPrev();
        }
    });
    controller.setMediaPlayer(this);
    controller.setAnchorView(findViewById(R.id.songList));
    controller.setEnabled(true);
}

And here's the code of the class:

package asus.example.com.player;

import android.content.Context;
import android.widget.MediaController;

public class MusicController extends MediaController {
    public MusicController(Context context) {
        super(context);
    }

    public void hide(){}
}`
Gourav
  • 2,746
  • 5
  • 28
  • 45
Sergei Mikhailovskii
  • 2,100
  • 2
  • 21
  • 43

1 Answers1

0

The show() method needs to be called for it to be shown on screen, when it's not created as part of an XML Layout. At the end of your setController() method, call this:

controller.show()
Gourav
  • 2,746
  • 5
  • 28
  • 45
Nelson Wright
  • 506
  • 9
  • 18
  • So, in such case I have the next problem. When I run the activity I have this: `Unable to add window -- token null is not valid; is your activity running?` – Sergei Mikhailovskii Jan 18 '19 at 17:48
  • @SergeiMikhailovskii If you're able to post more of your code, that would be useful, as at the moment I'm not sure how you're calling `setController()`, or from where. – Nelson Wright Jan 21 '19 at 17:24