android - how to resolve fatal exception 6 when multiple video playing at a time in videoview -
this code.
public class mainactivity extends activity { listview listview; customlistadapter adapter; private static progressdialog progressdialog; public static int currentitem; public static arraylist<string> videolist; public static mediacontroller mediacontroller ; boolean pauseonscroll = true; boolean pauseonfling = true; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_view); videolist = new arraylist<string>(); mediacontroller = new mediacontroller(mainactivity.this); videolist.add("http://journey.coderspreview.com/uploads/home_video/mov_bbb.mp4"); videolist.add("http://journey.coderspreview.com/uploads/experience/165/video/father-and-young-daughter.mp4"); videolist.add("http://journey.coderspreview.com/uploads/experience/185/video/couple-on-sail-boat.mp4"); videolist.add("http://journey.coderspreview.com/uploads/experience/39/video/vid-20141231-wa0006.mp4"); videolist.add("http://journey.coderspreview.com/uploads/experience/26/video/vid-20141216-wa0004.mp4"); listview = (listview) findviewbyid(r.id.list); listview.setadapter(new customlistadapter(this, videolist)); listview.setonscrolllistener(new abslistview.onscrolllistener() { private int mfirstvisiblerow = -1; private int mactiveitem = -1; @override public void onscrollstatechanged(abslistview view, int scrollstate) { } @override public void onscroll(abslistview view, int firstvisibleitem, int visibleitemcount, int totalitemcount) { int firstvisiblerow = listview.getfirstvisibleposition(); if( mfirstvisiblerow != firstvisiblerow ) { mfirstvisiblerow = firstvisiblerow; // cancel video of previous active item videoview prevactivevideoview = getvideoviewforrow(mactiveitem); if( prevactivevideoview != null ) { prevactivevideoview.pause(); } // start video of new active item mactiveitem = mfirstvisiblerow + 1; videoview newactivevideoview = getvideoviewforrow(mactiveitem); if(newactivevideoview != null) { newactivevideoview.start(); } } } private videoview getvideoviewforrow(int row) { int firstvisiblerow = listview.getfirstvisibleposition(); view rowview = listview.getchildat(row-firstvisiblerow); return (rowview == null) ? null : (videoview)rowview.findviewbyid(r.id.videoview); } }); } static class viewholderitem { textview textviewitem; videoview video; progressbar progressbar; } public class customlistadapter extends baseadapter { private activity activity; private layoutinflater inflater; private arraylist<string> videolist; public customlistadapter(activity activity, arraylist<string> videolist) { this.activity = activity; this.videolist = videolist; } @override public int getcount() { return videolist.size(); } @override public object getitem(int location) { return videolist.get(location); } @override public long getitemid(int position) { return position; } @suppresslint("newapi") @override public view getview(int position, view convertview, viewgroup parent) { final viewholderitem viewholder; if (convertview == null){ inflater = (layoutinflater) activity.getsystemservice(context.layout_inflater_service); convertview = inflater.inflate(r.layout.video_list_item, null); viewholder = new viewholderitem(); viewholder.video = (videoview)convertview.findviewbyid(r.id.videoview); viewholder.progressbar = (progressbar)convertview.findviewbyid(r.id.progress); viewholder.textviewitem =(textview)convertview.findviewbyid(r.id.txvposition); int pos; pos=viewholder.video.getcurrentposition(); log.d("current item position:",""+pos); convertview.settag(viewholder); }else{ viewholder = (viewholderitem) convertview.gettag(); } viewholder.textviewitem.settext("video"+position); // mediacontroller.setanchorview(viewholder.video); log.d("video url inadapter:", ""+videolist.tostring()); uri uri = uri.parse(videolist.get(position)); // viewholder.video.setmediacontroller(mediacontroller); viewholder.video.setvideouri(uri); //viewholder.video.start(); viewholder.video.setonpreparedlistener(new onpreparedlistener() { public void onprepared(mediaplayer arg0) { viewholder.progressbar.setvisibility(view.gone); viewholder.video.start(); } }); viewholder.video.setoninfolistener(new oninfolistener() { @override public boolean oninfo(mediaplayer mp, int what, int extra) { // todo auto-generated method stub log.d("buffrring start", "on_info"); if (mediaplayer.media_info_buffering_start == what) { viewholder.progressbar.setvisibility(view.visible); log.d("buffrring start", "" + what); } if (mediaplayer.media_info_buffering_end == what) { viewholder.progressbar.setvisibility(view.gone); log.d("buffrring end", "" + what); } if (mediaplayer.media_info_video_rendering_start == what) { viewholder.progressbar.setvisibility(view.gone); log.d("rendering end", "" + what); } return false; } }); viewholder.video.setonerrorlistener(new onerrorlistener() { @override public boolean onerror(mediaplayer mp, int what, int extra) { // todo auto-generated method stub log.d("error", "------>error" + + "/" + extra); if (extra != 0) { toast.maketext(mainactivity.this, "can't play video", toast.length_short).show(); } return false; } }); return convertview; } } }
i running multiple video @ time in listview after sometime video hang totally , app crashes giving fatal signal 6 error think memory isuue not sure how resolve issue?
Comments
Post a Comment