我想以片段形式显示视频 我已经用这个代码来播放它了,它起作用了
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();
但我想添加像播放停止简历这样的按钮..我该怎么办?
答案 0 :(得分:4)
将MediaController
与VideoView
:
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。