将后退按钮添加到MediaController

时间:2014-11-17 15:29:49

标签: android mediacontroller

我有像这样的MediaCrontroller的视频活动

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

如何向MediaController添加后退按钮? (系统导航栏不可用,因为它在专用设备上运行)

1 个答案:

答案 0 :(得分:2)

VideoPlayer是您的活动

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();
            }
        });
    }
}