java me - How to download and Play video in J2ME -
how download , play video in j2me?
my code working download
in samsung : download completed same bytes file writen in same bytes not supporting file format,
in nokia2690 download not completed, it's showing nullpointerexception
i have added code below
private void downloadstreams(string url, string filepath) throws ioexception { inputstream = null; stringbuffer sb = new stringbuffer(); httpconnection http = null; seek { alert = new alert("url stream::"); all.setstring("download stream!!:"); all.settimeout(1000); display.setcurrent(all); url = encodeurl(videourl); http = (httpconnection) connector.open(videourl); http.setrequestmethod(httpconnection.get); if (http.getresponsecode() == httpconnection.http_ok) { datainputstream datain = http.opendatainputstream(); byte[] buffer = new byte[(int) http.getlength()]; int read = -1; datain.readfully(buffer); datain.close(); http.close(); writefile(buffer, filepath); alert al = new alert("response::" + http.getresponsecode()); al.setstring("download complete!!:"); al.settimeout(3000); display.setcurrent(al, midp.dis); } } grab (exception ex) { alert al = new alert("downloading failed:::" + ex.tostring()); al.setstring("download failed" + ex.getmessage()); al.settimeout(alert.forever); display.setcurrent(al, midp.dis); } } public void writefile(byte[] videobuffer, string filepath) { connection con = null; outputstream os = null; seek { con = connector.open(filepath, connector.read_write); fileconnection fc = (fileconnection) con; if (!fc.exists()) { fc.create(); } os = fc.openoutputstream(); os.write(videobuffer); os.flush(); alert al = new alert("file write complete!!" + videobuffer.length); al.setstring("write complete!!:" + videobuffer.length); al.settimeout(3000); display.setcurrent(al, midp.dis); } grab (exception e) { } { seek { if (os != null) { os.close(); } if (con != null) { con.close(); } } grab (exception ex) { ex.printstacktrace(); } } } java-me download midp mmapi jsr75
No comments:
Post a Comment