You Are Here:

Community: Developer Discussion Boards

#1 Old Record audio, save it and send it to a server - 2009-04-16, 12:01

Join Date: Feb 2009
Posts: 16
Koryphäe
Offline
Registered User
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
Reply With Quote

#2 Old Re: Record audio, save it and send it to a server - 2009-04-16, 13:41

Join Date: Sep 2007
Posts: 115
Location: Thirunelveli
senthil_k
Offline
Regular Contributor
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
Reply With Quote

#3 Old Thumbs up Re: Record audio, save it and send it to a server - 2009-04-17, 08:56

Join Date: Sep 2008
Posts: 1,195
Location: DELHI
Send a message via Yahoo to jitu_goldie
jitu_goldie's Avatar
jitu_goldie
Offline
Forum Nokia Champion
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..
Reply With Quote

#4 Old Re: Record audio, save it and send it to a server - 2009-04-17, 09:25

Join Date: Feb 2009
Posts: 16
Koryphäe
Offline
Registered User
Thanks. Will use it.
Reply With Quote

#5 Old Question Re: Record audio, save it and send it to a server - 2009-04-21, 10:34

Join Date: Feb 2008
Posts: 9
vadimberman
Offline
Registered User
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?
Reply With Quote
Reply « Previous Thread | Next Thread »
Display Modes
Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules

You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Forum Jump

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia