android - Change position of Play video on item click in ListView -
i have listview, contain number of videos when click on item, video playing when scroll or down video become stop, referred https://github.com/danylovolokh/videoplayermanager working fine when click on item not 100 percent visible on screen this:
at time below item video playing, this:
i checked position in log when click on item getting right position in log, can do? please guys solve it. faced issue many days
my code below:
public class playvideo extends activity { private activity mactivity; private static final boolean show_logs = config.show_logs; private static final string tag = playvideo.class.getsimplename(); private arraylist<basevideoitem> mlist = new arraylist<>(); private string videoid = ""; public static int isvideoplay = 0; public static progressdialog pdialog; private final listitemsvisibilitycalculator mlistitemvisibilitycalculator = new singlelistviewitemactivecalculator(new defaultsingleitemcalculatorcallback(), mlist); private itemspositiongetter mitemspositiongetter; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.fragment_video_list_view); mactivity = playvideo.this; pdialog = new progressdialog(mactivity); pdialog.setmessage("loading"); pdialog.setcanceledontouchoutside(false); pdialog.setcancelable(true); try { mlist.add(itemfactory.createitemfromurl(mactivity, "http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4", r.drawable.video_sample_1_pic, mactivity, mvideoplayermanager)); mlist.add(itemfactory.createitemfromurl(mactivity, "http://www.androidbegin.com/tutorial/androidcommercial.3gp", r.drawable.video_sample_3_pic, mactivity, mvideoplayermanager)); mlist.add(itemfactory.createitemfromurl(mactivity, "http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4", r.drawable.video_sample_4_pic, mactivity, mvideoplayermanager)); mlist.add(itemfactory.createitemfromurl(mactivity, "http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4", r.drawable.video_sample_1_pic, mactivity, mvideoplayermanager)); mlist.add(itemfactory.createitemfromurl(mactivity, "http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4", r.drawable.video_sample_2_pic, mactivity, mvideoplayermanager)); mlist.add(itemfactory.createitemfromurl(mactivity, "http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4", r.drawable.video_sample_3_pic, mactivity, mvideoplayermanager)); mlist.add(itemfactory.createitemfromurl(mactivity, "http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4", r.drawable.video_sample_4_pic, mactivity, mvideoplayermanager)); } catch (ioexception e) { throw new runtimeexception(e); } mlistview = (listview) findviewbyid(r.id.list_view); videolistviewadapter videolistviewadapter = new videolistviewadapter(mvideoplayermanager, mactivity, mlist); mlistview.setadapter(videolistviewadapter); mlistview.setonitemclicklistener(new adapterview.onitemclicklistener() { @override public void onitemclick(adapterview<?> parent, view view, int position, long id) { log.d("isvideo------------", string.valueof(isvideoplay)); if (isvideoplay == 0) { pdialog.show(); log.d("position....", string.valueof(position)); mitemspositiongetter = new listviewitempositiongetter(mlistview); log.d("mlistview.getfirstvisibleposition()....", string.valueof(mlistview.getfirstvisibleposition())); log.d("mlistview.getlastvisibleposition()....", string.valueof(mlistview.getfirstvisibleposition())); log.d("mitemspositiongetter....", string.valueof(mitemspositiongetter)); mlistitemvisibilitycalculator.onscrollstateidle(mitemspositiongetter, mlistview.getfirstvisibleposition(), mlistview.getlastvisibleposition()); } } }); mlistview.setonscrolllistener(new abslistview.onscrolllistener() { @override public void onscrollstatechanged(abslistview view, int scrollstate) { mscrollstate = scrollstate; if (scrollstate == scroll_state_idle && !mlist.isempty()) { if(isvideoplay == 1){ isvideoplay = 0; pdialog.dismiss(); } } } @override public void onscroll(abslistview view, int firstvisibleitem, int visibleitemcount, int totalitemcount) { if (!mlist.isempty()) { if(isvideoplay == 1){ isvideoplay = 0; pdialog.dismiss(); } } } }); } private final videoplayermanager<metadata> mvideoplayermanager = new singlevideoplayermanager(new playeritemchangelistener() { @override public void onplayeritemchanged(metadata metadata) { if (show_logs) logger.v(tag, "onplayeritemchanged " + metadata); } }); private int mscrollstate = abslistview.onscrolllistener.scroll_state_idle; private listview mlistview; @override public void onstop() { super.onstop(); // have stop playback in onstop mvideoplayermanager.resetmediaplayer(); } }
Comments
Post a Comment