首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >VideoView in CustomDialog Android

VideoView in CustomDialog Android
EN

Stack Overflow用户
提问于 2016-02-20 09:13:32
回答 1查看 2.6K关注 0票数 2

我想使用VideView在自定义对话框中播放一个视频,但是在对话框中,我只得到标题,而不是VideoView或button.Please帮助,还有比自定义对话框更好的方式在活动上显示视频吗?

代码语言:javascript
复制
final Dialog dialog = new Dialog(getActivity());
                    dialog.setContentView(R.layout.introvid);
                    dialog.setTitle("Title...");

                    // set the custom dialog components - text, image and button

                    final VideoView viz = (VideoView) dialog.findViewById(R.id.vid123);
                    Uri vidUri = Uri.parse(feedob);
                    vid.setVideoURI(vidUri);
                    vid.start();

                    Button dialogButton = (Button) dialog.findViewById(R.id.dialogButtonOK);
                    // if button is clicked, close the custom dialog
                    dialogButton.setOnClickListener(new OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            dialog.dismiss();
                        }
                    });

                    dialog.show();

自定义对话框的布局

代码语言:javascript
复制
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent" >

<VideoView
    android:id="@+id/vid123"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    />


    <Button
        android:id="@+id/dialogButtonOK"
        android:layout_width="100px"
        android:layout_height="wrap_content"
        android:text="Back "
        android:layout_marginTop="5dp"
        android:layout_marginRight="5dp"
        android:layout_below="@+id/vid123"
        />

</RelativeLayout>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-02-20 09:16:23

试试这个,它会起作用的

代码语言:javascript
复制
final Dialog dialog = new Dialog(yourclassname.this);// add here your class name
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setContentView(R.layout.yourxml);//add your own xml with defied with and height of videoview
    dialog.show();
    WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
    LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    lp.copyFrom(dialog.getWindow().getAttributes());
    dialog.getWindow().setAttributes(lp);
    uriPath= "android.resource://" + getPackageName() + "/" + R.raw.yourvid;

    getWindow().setFormat(PixelFormat.TRANSLUCENT);
    Log.v("Vidoe-URI", uriPath+ "");
    mVideoView.setVideoURI(Uri.parse(uriPath));
    mVideoView.start();
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35521216

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档