如何在片段中播放视频

时间:2015-03-15 16:35:15

标签: android android-fragments android-videoview

我想以片段形式显示视频 我已经用这个代码来播放它了,它起作用了

   View rootView = inflater.inflate(R.layout.quranic_section, container, false);

    VideoView view = (VideoView)rootView.findViewById(R.id.video_view);
    String path = "android.resource://" + getActivity().getPackageName() + "/" + R.raw.howtopray;
    view.setVideoURI(Uri.parse(path));
    view.start();

但我想添加像播放停止简历这样的按钮..我该怎么办?

1 个答案:

答案 0 :(得分:4)

MediaControllerVideoView

一起使用
View rootView = inflater.inflate(R.layout.quranic_section, container, false);
MediaController mc= new MediaController(getActivity());

VideoView view = (VideoView)rootView.findViewById(R.id.video_view);
String path = "android.resource://" + getActivity().getPackageName() + "/" + R.raw.howtopray;
view.setVideoURI(Uri.parse(path));
view.setMediaController(mc);
view.start();

修改

MediaController构造函数将Context作为参数。添加了getActivity()方法,为MediaController构造函数提供了Context。