J2ME: Recording AV and sending to a Server

14/04/06 Permalink

For this to work you will need a servlet supporting server and a phone capable of capturing audio/video/images from Java. You could use this for instance with the Sony Ericsson K700i for sending an image because it supports capture=image/jpeg. Check the Calibrator to see what phones support what capture methods.

Client

      //baos is the ByteArrayOutputStream that contains the binary data
      //You can usually attach this stream to the Control (VideoControl/RecordControl) 
      //of Manager.createPlayer(... or with images getSnapShot(encoding)
      c = (HttpConnection) Connector.open(uploadURL,Connector.READ_WRITE); 
      c.setRequestMethod(HttpConnection.POST);
      os = c.openDataOutputStream();  
      byte[] data = baos.toByteArray();
      baos.reset();
      baos = null;
            
      os.writeInt(data.length); //AA
      os.write(data);    //BB
      os.flush();
Server

     DataInputStream dis = new DataInputStream(request.getInputStream());
     int filelen = dis.readInt(); //AA
     byte[] data = new byte[filelen]; 
     dis.readFully(data); //BB

There's a fuller example here.

Share It: Digg | del.icio.us | Furl | reddit | Facebook | Yahoo! | Send to Phone

mobile-utopia.com | Feedback