4

我刚刚创建了一个自定义 DialogFragment,里面有一个 VideoView,但我遇到了一些问题。

  • 视频正在播放,但出于某种奇怪的原因,视频顶部有一种黑色且非常透明的层。当然,我尝试从我的应用程序中的其他地方(不是对话窗口)播放相同的视频,并且它显示正确。很奇怪...

  • 此外,对话框窗口的顶部和左侧边框消失 - 如果删除 VideoView,它们不会消失。

任何想法?提前致谢!

编辑

控制器

public class VideoPlayerFragment extends DialogFragment
{
    String json_string;

    // Constructor
    public static VideoPlayerFragment newInstance(String json_string_arg)
    {
        VideoPlayerFragment fragment = new VideoPlayerFragment();

        Bundle arguments = new Bundle();
        arguments.putString("json_string", json_string_arg);
        fragment.setArguments(arguments);

        return fragment;
    }


    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);

        // Set style
        setStyle(DialogFragment.STYLE_NO_TITLE, 0);
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
    {
        View view = inflater.inflate(R.layout.video_player, container, false);

        return view;
    }


    @Override
    public void onActivityCreated(Bundle savedInstanceState)
    {
         super.onActivityCreated(savedInstanceState);

         // Set video holder
         VideoView video_view = (VideoView) getView().findViewById(R.id.video_view);

         // Set URL
         Uri video = Uri.parse("android.resource://" + getActivity().getPackageName() + "/" + R.raw.test);
         video_view.setVideoURI(video);

         // Start video
         video_view.start();
    }
}

看法

    <LinearLayout android:id="@+id/video"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="@dimen/video_player_margin"
        android:orientation="vertical" >

        <VideoView android:id="@+id/video_view"
            android:layout_gravity="center_horizontal|center_vertical"
            android:layout_width="700dp"
            android:layout_height="400dp" />

    </LinearLayout>
4

2 回答 2

0

我遇到了同样的情况:DialogFragment中的videoview。

问题1:这里可以帮助你,我也发现了;

问题 2:我认为您在方法 onActivityCreated() 中需要这些代码(此行隐藏黑色边框)

getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));

ps:这是我在 onCreateView(,,) 中的初始化代码

if (getShowsDialog())
    {
        getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);

        getDialog().setCanceledOnTouchOutside(false);
    }
于 2013-08-09T10:09:41.807 回答
0
     public class VideoPlayerFragment extends DialogFragment
        {
            String json_string;

            // Constructor
            public static VideoPlayerFragment newInstance(String json_string_arg)
            {
                VideoPlayerFragment fragment = new VideoPlayerFragment();

                Bundle arguments = new Bundle();
                arguments.putString("json_string", json_string_arg);
                fragment.setArguments(arguments);

                return fragment;
            }

        @Override
            public Dialog onCreateDialog(Bundle savedInstanceState) {
                Dialog dialog = new Dialog(getActivity());
                dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
                dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
                dialog.getWindow().setLayout(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
                dialog.getWindow().setSoftInputMode(
                        WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN|WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
                dialog.setCancelable(true);
                View parent= getActivity().getLayoutInflater().inflate(R.layout.video_player, null);
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
dialog.setContentView(parent, layoutParams);
                return dialog;
            }
         @Override
            public void onActivityCreated(Bundle savedInstanceState)
            {
                 super.onActivityCreated(savedInstanceState);

                 // Set video holder
                 VideoView video_view = (VideoView) getView().findViewById(R.id.video_view);

                 // Set URL
                 Uri video = Uri.parse("android.resource://" + getActivity().getPackageName() + "/" + R.raw.test);
                 video_view.setVideoURI(video);

                 // Start video
                 video_view.start();
            }

朋友尝试上面的代码。而不是创建视图尝试创建没有对话框标题的 onCreateDialog ....

于 2013-01-30T04:33:11.787 回答