How to stop Videoview from playing inside a viewPager when fragment is changed -
i want stop videoview playing inside viewpager when fragment change. problem in code when change or next fragment video still playing.
here code main activity class
private void setupviewpager(viewpager viewpager) { viewpageradapter adapter = new viewpageradapter(getsupportfragmentmanager()); adapter.addfragment(new fragmentstepone(), "1"); adapter.addfragment(new fragmentsteptwo(), "2"); viewpager.setadapter(adapter); } class viewpageradapter extends fragmentstatepageradapter { private final list<fragment> mfragmentlist = new arraylist<>(); private final list<string> mfragmenttitlelist = new arraylist<>(); public viewpageradapter(fragmentmanager manager) { super(manager); } @override public fragment getitem(int position) { return mfragmentlist.get(position); } @override public int getcount() { return mfragmentlist.size(); } public void addfragment(fragment fragment, string title) { mfragmentlist.add(fragment); mfragmenttitlelist.add(title); }
and here code fragment class
public class fragmentstepone extends fragment{ public fragmentstepone() { } videoview video; @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); } @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { // inflate layout fragment view rootview = inflater.inflate(r.layout.fragment_step_two, container, false); video = (videoview) rootview.findviewbyid(r.id.videoview); uri uri = uri.parse("android.resource://"+ getactivity().getpackagename()+"/"+ r.raw.video); video.setvideouri(uri); mediacontroller mc=new mediacontroller(getcontext()); mc.setanchorview(video); video.setmediacontroller(mc); video.requestfocus(); return rootview; }
please thank in advance
Comments
Post a Comment