I want to display video in fragment I have used this code to play it, it worked
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();
but i want to add button like play stop resume .. how can I do it ?
Use MediaController
with 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();
Edit
MediaController constructor takes Context as a parameter. Added getActivity() method to provide Context to MediaController constructor.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With