Recording midlet with save function

Im making a midlet that records audio and saves it to phone's file system. I get the application to run in emulator but when in phone (Sony Ericsson V800) i immediately get error Cannot create a DataSource for: null. Here is the code i'm trying to get to work: (i tried to change the file:///test.wav to file:///e:/test.wav but it didn't help. Also i got a version of this code without the save function but it doesn't work in phone either, it just says error.

import javax.microedition.midlet.*;

import javax.microedition.lcdui.*;

import javax.microedition.media.*;

import javax.microedition.media.control.RecordControl;

publicclass SaveCapturedAudioMIDletextends MIDlet

implements CommandListener{

// the display items

private Display display =null;

private Alert alert =null;

private Command exitCommand =null;

// players and controls

private Player capturePlayer =null;

private Player playbackPlayer =null;

private RecordControl rControl =null;

privateboolean error =false;

public SaveCapturedAudioMIDlet(){

// create the display

display = Display.getDisplay(this);

alert =new Alert("Message");

alert.setTimeout(Alert.FOREVER);

alert.setString("Capturing for 10 seconds. Say something intelligent!");

exitCommand =new Command("Exit", Command.EXIT, 1);

alert.addCommand(exitCommand);

alert.setCommandListener(this);

try{

// create the capture player

capturePlayer = Manager.createPlayer("capture://audio");

if (capturePlayer !=null){

// if created, realize it

capturePlayer.realize();

// and grab the RecordControl

rControl = (RecordControl)capturePlayer.getControl(

"javax.microedition.media.control.RecordControl");

// set the alert as the current item

display.setCurrent(alert);

// if it is null throw exception

if(rControl ==null)thrownew Exception("No RecordControl available");

// and set the destination for this captured data

rControl.setRecordLocation("file:///test.wav");

}else{

thrownew Exception("Capture Audio Player is not available");

}

}catch(Exception e){

error(e);

}

}

publicvoid startApp(){

if(error)return;

try{

// first start the corresponding recording player

capturePlayer.start();

// and then start the RecordControl

rControl.startRecord();

// now record for 10 seconds

Thread.sleep(10000);

// stop recording after time is up

rControl.stopRecord();

// commit the recording

rControl.commit();

// stop the Player instance

capturePlayer.stop();

// and close it to release the microphone

capturePlayer.close();

// finally, create a Player instance to playback

// check your device documentation to find out the root.

// The following will work on devices that have the root

// specified as shown

playbackPlayer = Manager.createPlayer("file:///test.wav");

// and start it

playbackPlayer.start();

}catch(Exception e){

error(e);

}

}

publicvoid pauseApp(){

}

publicvoid destroyApp(boolean unconditional){

if(capturePlayer !=null) capturePlayer.close();

if(playbackPlayer !=null) playbackPlayer.close();

}

publicvoid commandAction(Command cmd, Displayable disp){

if(cmd == exitCommand){

destroyApp(true);

notifyDestroyed();

}

}

// general purpose error method, displays on screen as well to output

privatevoid error(Exception e){

alert.setString(e.getMessage());

alert.setTitle("Error");

display.setCurrent(alert);

e.printStackTrace();

error =true;

}

}

[7577 byte] By [xaozona] at [2007-11-27 4:53:52]
# 1

see this:

http://www.hcilab.org/documents/tutorials/AudioTest/index.html

I think the problem is the url passed to player "file:///test.wav"

I think you must read the file from the filesystem with jsr 75 api (Fileconnection etc.) and then make a byte stream in order to pass it to the Manager.createPlayer().

PeppeMEa at 2007-7-12 10:08:25 > top of Java-index,Java Mobility Forums,Java ME Technologies...