| Reply | « Previous Thread | Next Thread » |
|
I would like to record an audioclip of 8 seconds, save it to a file on the mobile phone and send it to an apache server of mine, which uses php. How do I achieve that, is there a tutorial for this procedure?
Regards |
|
Hi
To record and save aduio: public void recordAudio() { try { ByteArrayOutputStream output = null; player = Manager.createPlayer("capture://audio"); player.realize(); rc = (RecordControl) player.getControl("RecordControl"); output = new ByteArrayOutputStream(); rc.setRecordStream(output); rc.startRecord(); player.start(); } catch (Exception e) { e.printStackTrace(); } } public void stopRecord() { try { rc.commit(); player.close(); } catch (IOException ex) { ex.printStackTrace(); } } For sending audio to server please refer nokia wiki. if not available tell me i will give you Senthil |
|
for save the recording to filesystem and upload to server..
after commit the recording.. copy the data(bytes of bytearrayoutputstream) to byte array byte [] data = baos.tobytearray(); copy the above data to another byte array byte[] newdata = new byte(data.length); copy the whole data to newdata byte by byte.. write to filesystem.. FileConnection conn = (FileConnection) Connector.open("file:///E:/testing.3gp",Connector.WRITE); conn.create(); OutputStream out = conn.openOutputStream(); out.write(data); close the connection and streams.. for upload to server public synchronized void run() { ///// Define a new Http Connection HttpConnection httpCon = null; OutputStream dos=null; InputStream is = null; try { /// Opening Http Connection httpCon = (HttpConnection) Connector.open(url,Connector.READ_WRITE,false); if(data!=null) { httpCon.setRequestMethod(HttpConnection.POST); httpCon.setRequestProperty("Content-Length",""+data.length); /// Open a output stream to write data dos=httpCon.openOutputStream(); /// write data to output stream dos.write(newdata); dos.flush(); } /// check for Server response code int responseCode = httpCon.getResponseCode(); if (responseCode != HttpConnection.HTTP_OK) { throw new IOException("Http Response Code:" + responseCode); } is = httpCon.openInputStream(); /** read return data from server */ } catch (IOException ex) { System.out.println("IOException"); ex.printStackTrace(); } catch(SecurityException sex){ System.out.println("Security Exception"); sex.printStackTrace(); } catch (Exception ex) { ex.printStackTrace(); } catch (OutOfMemoryError oomer) { System.out.println("Out OF Memory Exception"); oomer.printStackTrace(); } finally { try { is.close(); if(dos!=null) dos.close(); httpCon.close(); } catch (Exception ex) { ex.printStackTrace(); } } } check and reply.. thanks, jitu_goldie.. KEEP TRYING.. |
| jitu_goldie |
| View Public Profile |
| Find all posts by jitu_goldie |
|
Thanks. Will use it.
|
|
A question which may be potentially interesting to people looking to accomplish the same: why is it in the standard Sun J2ME simulator, the resulting wave file is incompatible to most standard players (Windows Media Player, etc.)?
I tried fiddling with the bitrate, endian, signed, but couldn't get the right combination! Eventually I had to give it up and switch to AMR, then convert it on the server... Not the most elegant solution. Any hints how to make the wave output more standard? |
| vadimberman |
| View Public Profile |
| Find all posts by vadimberman |
| Reply | « Previous Thread | Next Thread » |
| Thread Tools | Search this Thread |
|---|---|