媒体控制器从不在视频视图中显示

时间:2014-09-01 02:26:53

标签: android media android-mediaplayer android-videoview mediacontroller

我搜索了许多相同答案的主题,

但看起来对我不起作用还有很多人。

Create Custom Media Controller

public class CcMediaController extends MediaController {

ImageButton mCCBtn;
Context mContext;
AlertDialog mLangDialog;

public CcMediaController(Context context) {
    super(context);
    mContext = context;
}

@Override
public void setAnchorView(View view) {
    super.setAnchorView(view);

    FrameLayout.LayoutParams frameParams = new FrameLayout.LayoutParams(
            LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    frameParams.gravity = Gravity.RIGHT|Gravity.TOP;

    View v = makeCCView();
    addView(v, frameParams);
}

private View makeCCView() {
    mCCBtn = new ImageButton(mContext);
    mCCBtn.setImageResource(R.drawable.abc_ab_bottom_solid_dark_holo);

    mCCBtn.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            Builder builder = new AlertDialog.Builder(mContext);
            builder.setSingleChoiceItems(R.array.array, 0, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    //Save Preference and Dismiss the Dialog here
                    Toast.makeText(mContext, "Which ::: "+which, Toast.LENGTH_LONG).show();
                }

            });
            mLangDialog = builder.create();
            mLangDialog.show();
        }
    });

    return mCCBtn;
}
}

Put Custom Media Controller into Video View by using setAnchorView()

CcMediaController mMc = new CcMediaController(this);

// FrameLayout.LayoutParams lp = new FameLayout.LayoutParams(
// FrameLayout.LayoutParams.MATCH_PARENT, 
// FrameLayout.LayoutParams.WRAP_CONTENT);
// lp.gravity = Gravity.BOTTOM;
// mMc.setLayoutParams(lp);
//
// ((ViewGroup) mMc.getParent()).removeView(mMc);
//
// (new VideoControllerView(this)).addView(mMc);

        // set play video view dialog details photo
        mMc.setAnchorView(mVvPlayVideoInDetail);
        mMc.setMediaPlayer(mVvPlayVideoInDetail);

        mVvPlayVideoInDetail.requestFocus();
        mVvPlayVideoInDetail.setBackgroundColor(Color.WHITE);
        mVvPlayVideoInDetail.setMediaController(mMc);
        mVvPlayVideoInDetail.setZOrderOnTop(true);

VideoView.xml

<VideoView
            android:alpha="0.5"
            android:background="@android:color/transparent"
            android:id="@+id/vv_play_video_dialog_detail"
            android:layout_height="250dp"
            android:layout_width="match_parent"
            android:layout_weight="1"
            android:visibility="visible"
            />

我将视频视图显示为高度= 240dp的对话框的一部分,而不是全屏。

仍未奏效,

请帮助我show Media Controller on Video View correctly

由于

1 个答案:

答案 0 :(得分:0)

尝试致电setZOrderMediaOverlay(true); 这是由于setzorderontop(true)视频观看次数无法显示,因此调用setZOrderMediaOverlay(true);会覆盖setzorderontop(true)