Showing posts with label mobile. Show all posts
Showing posts with label mobile. Show all posts

Wednesday, November 4, 2009

Sample J2Me Midlet for sound recording



import java.io.*;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.media.*;
import javax.microedition.media.control.*;

public class VoiceRecordMidlet extends MIDlet {
private Display display;

public void startApp() {
display = Display.getDisplay(this);
display.setCurrent(new VoiceRecordForm());
}

public void pauseApp() {
}

public void destroyApp(boolean unconditional) {
notifyDestroyed();
}
}

class VoiceRecordForm extends Form implements CommandListener {
private StringItem message;
private StringItem errormessage;
private final Command record, play;
private Player player;
private byte[] recordedAudioArray = null;
public VoiceRecordForm() {
super("Recording Audio");
message = new StringItem("", "Select Record to start recording.");
this.append(message);
errormessage = new StringItem("", "");
this.append(errormessage);
record = new Command("Record", Command.OK, 0);
this.addCommand(record);
play = new Command("Play", Command.BACK, 0);
this.addCommand(play);
this.setCommandListener(this);
}
public void commandAction(Command comm, Displayable disp) {
if (comm == record) {
Thread t = new Thread() {
public void run() {
try {
player = Manager.createPlayer("capture://audio?encoding=pcm");
player.realize();
RecordControl rc = (RecordControl) player.getControl("RecordControl");
ByteArrayOutputStream output = new ByteArrayOutputStream();
rc.setRecordStream(output);
rc.startRecord();
player.start();
message.setText("Recording...");
Thread.sleep(5000);
message.setText("Recording Done!");
rc.commit();
recordedAudioArray = output.toByteArray();
player.close();
} catch (Exception e) {
errormessage.setLabel("Error");
errormessage.setText(e.toString());
}
}
};
t.start();

}
else if (comm == play) {
try {
ByteArrayInputStream recordedInputStream = new ByteArrayInputStream(recordedAudioArray);
Player p2 = Manager.createPlayer(recordedInputStream, "audio/basic");
p2.prefetch();
p2.start();
} catch (Exception e) {
errormessage.setLabel("Error");
errormessage.setText(e.toString());
}
}
}
}

Saturday, June 6, 2009

Hello world Midlet


import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Form;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;


public class LoginScreen extends MIDlet {

public LoginScreen() {
// TODO Auto-generated constructor stub
}

protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
// TODO Auto-generated method stub

}

protected void pauseApp() {
// TODO Auto-generated method stub

}

protected void startApp() throws MIDletStateChangeException {
// TODO Auto-generated method stub

Form f = new Form("Login Form");
Display d = Display.getDisplay(this);
d.setCurrent(f);

f.append("Hello");

}

}

Java Me Notes

Links

Main site

http://java.sun.com/javame/index.jsp

Download

http://java.sun.com/products/sjwtoolkit/download.html

Eclipse plugin

http://download.eclipse.org/dsdp/mtj/updates/0.9/stable/

Need to use eclipse to export jad and jar for the project (which is in deploy)


Conventions

startApp() --> like main

import javax.microedition.lcdui.*; //required to use display

Display // interface with phone screen

Form //set up the screen then attach it to display

myform.append("some text"); //a label

Friday, December 19, 2008

Blackberry desktop manager

Working with the BDM has not been a general pleasure for me and other technicians where I work. It doesn't sync all the time, most likely due to corrupt organizer data and/or buggy software. The weird thing is that it was working kind alright when we had an Exchange server, but it got crappy when we migrated to a MAPI connector with Sun. I got it syncing by installing the exchange redirector BDM (we're still using outlook) and disabling redirection?! In the process of stumbling on this, I became familiar with just about every troubleshooting BB trick. Fun!