Add backbutton to MediaController

898 views Asked by At

I have a Video-Activity with a MediaCrontroller like this

    ctlr = new MediaController(this);
    ctlr.setMediaPlayer(mVV);
    mVV.setMediaController(ctlr);
    ctlr.show();

how can i add a back Button to the MediaController? (The system navigation bar is not available since it runs on a dedicated device)

1

There are 1 answers

0
wutzebaer On BEST ANSWER

Where VideoPlayer is your activity

private static class BackMediaController extends MediaController {
    private VideoPlayer player;

    public BackMediaController(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public BackMediaController(Context context, VideoPlayer player) {
        super(context);
        this.player = player;
    }

    @Override
    public void setAnchorView(View view) {
        super.setAnchorView(view);
        ImageView closeButton = new ImageView(getContext());
        closeButton.setImageResource(android.R.drawable.ic_menu_close_clear_cancel);
        float padding = getResources().getDimension(R.dimen.defaultSpacing);
        closeButton.setPadding((int) padding, (int) padding, (int) padding, (int) padding);
        FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        params.gravity = Gravity.START;
        addView(closeButton, params);
        closeButton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                player.finish();
            }
        });
    }
}