如何在片段中播放视频
How to play video in fragment
我想分片显示视频
我已经用这个代码玩过了,很有效
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();
但我想添加播放停止恢复等按钮..我该怎么做?
将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 构造函数提供上下文。
我想分片显示视频 我已经用这个代码玩过了,很有效
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();
但我想添加播放停止恢复等按钮..我该怎么做?
将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 构造函数提供上下文。