i'm trying create dynamic videoview in class , call class method in mainactivity. contains errors.
package com.gst_sdk_tutorials.tutorial_4; import java.io.file; import java.util.arraylist; import android.app.activity; import android.content.context; import android.database.cursor; import android.database.sqlite.sqlitedatabase; import android.media.mediaplayer; import android.widget.relativelayout; import android.widget.toast; import android.widget.videoview; public class videoclass extends activity { videoview v; context vcontext; sqlitedatabase sqldb; string tmp; relativelayout rl; relativelayout.layoutparams params; cursor cursertemplatevideo; string tmpv; int videoid; int videowidth; int videoheight; int videox; int videoy; int videocount; int videolistcount=2; arraylist<string> videolist = new arraylist<string>(); public videoclass(string tmp, sqlitedatabase sqldb, relativelayout rl, relativelayout.layoutparams params,context vcontext) { videolist.add("1.mp4"); videolist.add("2.mp4"); this.vcontext = vcontext; this.sqldb = sqldb; this.tmp = tmp; this.rl = rl; this.params = params; getvideozonelist(); } public void getvideozonelist() { try { cursertemplatevideo = sqldb.rawquery("select * templatevideo template='"+tmp+"'", null); if(cursertemplatevideo.getcount()==0) { return; } while(cursertemplatevideo.movetonext()) { tmpv = cursertemplatevideo.getstring(0); videoid = integer.parseint(cursertemplatevideo.getstring(1)); videowidth = integer.parseint(cursertemplatevideo.getstring(2)); videoheight = integer.parseint(cursertemplatevideo.getstring(3)); videox = integer.parseint(cursertemplatevideo.getstring(4)); videoy = integer.parseint(cursertemplatevideo.getstring(5)); newvideoview(videoid,videowidth,videoheight,videox,videoy); } } { if (cursertemplatevideo!=null) { cursertemplatevideo.close(); } } } public void newvideoview(int count, int w, int h, int x, int y) { v = new videoview(vcontext); v.setid(count); v.setx(x); v.sety(y); params = new relativelayout.layoutparams(w,h); //params.setmargins(5, 5, 5, 5); rl.addview(v,params); playvideo(); } public void playvideo() { v.setvideopath("/sdcard/signage/videos/"+videolist.get(0)); v.start(); v.setoncompletionlistener(new mediaplayer.oncompletionlistener() { @override public void oncompletion(mediaplayer mp) { try { file dir1 = new file("/sdcard/signage/videos/"); final file file1[]=dir1.listfiles(); videocount++; if(file1.length==0) { v.stopplayback(); } else { if(videocount<videolistcount) { string filepath = file1[videocount].tostring(); file file = new file(filepath); long filesize = file.length(); if(filesize == 0) { file.delete(); videocount++; } else if(videocount >= videolistcount) { videocount=0; } else { try { v.setvideopath("/sdcard/signage/videos/"+videolist.get(videocount)); v.start(); } catch (exception e) { toast.maketext(getbasecontext(),"video play error!",toast.length_long).show(); } } } else { videocount=0; v.setvideopath("/sdcard/signage/videos/"+videolist.get(videocount)); v.start(); } } } catch (exception e) { toast.maketext(getbasecontext(),"video play error!",toast.length_long).show(); } } }); } }
public class mainactivity extends activity {
context vcontext; relativelayout rl; relativelayout.layoutparams params; sqlitedatabase sqldb; string tmp = "3"; public createsqldbclass dbclass = null; public videoclass videoclass = null; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); requestwindowfeature(window.feature_no_title); getwindow().setflags(windowmanager.layoutparams.flag_fullscreen, windowmanager.layoutparams.flag_fullscreen); view decorview = getwindow().getdecorview(); int uioptions = view.system_ui_flag_fullscreen | view.system_ui_flag_hide_navigation; decorview.setsystemuivisibility(uioptions); //decorview.setsystemuivisibility(8); decorview.onwindowfocuschanged(true); setcontentview(r.layout.activity_main); sqldb = openorcreatedatabase("signage",context.mode_private, null); rl = (relativelayout) findviewbyid(r.id.container); dbclass = new createsqldbclass(); videoclass = new videoclass(tmp,sqldb,rl,params,vcontext); if (savedinstancestate == null) { getfragmentmanager().begintransaction() .add(r.id.container, new placeholderfragment()).commit(); } } @override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. getmenuinflater().inflate(r.menu.main, menu); return true; } @override public boolean onoptionsitemselected(menuitem item) { // handle action bar item clicks here. action bar // automatically handle clicks on home/up button, long // specify parent activity in androidmanifest.xml. int id = item.getitemid(); if (id == r.id.action_settings) { return true; } return super.onoptionsitemselected(item); } /** * placeholder fragment containing simple view. */ public static class placeholderfragment extends fragment { public placeholderfragment() { } @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { view rootview = inflater.inflate(r.layout.fragment_main, container, false); return rootview; } }
}
hear error messages...
01-01 07:26:06.060: d/androidruntime(5687): shutting down vm 01-01 07:26:06.060: w/dalvikvm(5687): threadid=1: thread exiting uncaught exception (group=0x41a43930) 01-01 07:26:06.070: e/androidruntime(5687): fatal exception: main 01-01 07:26:06.070: e/androidruntime(5687): java.lang.runtimeexception: unable start activity componentinfo{com.gst_sdk_tutorials.tutorial_4/com.gst_sdk_tutorials.tutorial_4.mainactivity}: java.lang.indexoutofboundsexception: invalid index 0, size 0 01-01 07:26:06.070: e/androidruntime(5687): @ android.app.activitythread.performlaunchactivity(activitythread.java:2180) 01-01 07:26:06.070: e/androidruntime(5687): @ android.app.activitythread.handlelaunchactivity(activitythread.java:2230) 01-01 07:26:06.070: e/androidruntime(5687): @ android.app.activitythread.access$600(activitythread.java:141) 01-01 07:26:06.070: e/androidruntime(5687): @ android.app.activitythread$h.handlemessage(activitythread.java:1234) 01-01 07:26:06.070: e/androidruntime(5687): @ android.os.handler.dispatchmessage(handler.java:99) 01-01 07:26:06.070: e/androidruntime(5687): @ android.os.looper.loop(looper.java:137) 01-01 07:26:06.070: e/androidruntime(5687): @ android.app.activitythread.main(activitythread.java:5041) 01-01 07:26:06.070: e/androidruntime(5687): @ java.lang.reflect.method.invokenative(native method) 01-01 07:26:06.070: e/androidruntime(5687): @ java.lang.reflect.method.invoke(method.java:511) 01-01 07:26:06.070: e/androidruntime(5687): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:793) 01-01 07:26:06.070: e/androidruntime(5687): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:560) 01-01 07:26:06.070: e/androidruntime(5687): @ dalvik.system.nativestart.main(native method) 01-01 07:26:06.070: e/androidruntime(5687): caused by: java.lang.indexoutofboundsexception: invalid index 0, size 0 01-01 07:26:06.070: e/androidruntime(5687): @ java.util.arraylist.throwindexoutofboundsexception(arraylist.java:251) 01-01 07:26:06.070: e/androidruntime(5687): @ java.util.arraylist.get(arraylist.java:304) 01-01 07:26:06.070: e/androidruntime(5687): @ com.gst_sdk_tutorials.tutorial_4.videoclass.playvideo(videoclass.java:94) 01-01 07:26:06.070: e/androidruntime(5687): @ com.gst_sdk_tutorials.tutorial_4.videoclass.newvideoview(videoclass.java:89) 01-01 07:26:06.070: e/androidruntime(5687): @ com.gst_sdk_tutorials.tutorial_4.videoclass.getvideozonelist(videoclass.java:67) 01-01 07:26:06.070: e/androidruntime(5687): @ com.gst_sdk_tutorials.tutorial_4.videoclass.(videoclass.java:44) 01-01 07:26:06.070: e/androidruntime(5687): @ com.gst_sdk_tutorials.tutorial_4.mainactivity.oncreate(mainactivity.java:154) 01-01 07:26:06.070: e/androidruntime(5687): @ android.app.activity.performcreate(activity.java:5113) 01-01 07:26:06.070: e/androidruntime(5687): @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1080) 01-01 07:26:06.070: e/androidruntime(5687): @ android.app.activitythread.performlaunchactivity(activitythread.java:2144) 01-01 07:26:06.070: e/androidruntime(5687): ... 11 more 01-01 07:26:06.420: i/process(5687): sending signal. pid: 5687 sig: 9
Comments
Post a Comment