PDA

View Full Version : [J2ME]creazione file+registrazione+play+invio


Kl@
16-04-2007, 09:08
Buongiorno a tutti,
sono nuovo del forum, volevo chiedere se, qualcuno, come da oggetto ha mai sviluppato un progetto simile per un cellulare??
Io devo farlo per la tesi e per effettuare le prove utilizzo un Nokia N91. sono gia' riuscito ad acquisire la traccia e ad inviarla ma i miei problemi sono i seguenti:
1- ho scritto una funzione che crea un file vuoto in cui, successivamente andro' a registrare la traccia audio, ma al momento della registrazione non accade nulla. Questo e' molto strano perche' se il file lo "creo" a mano,collegando il cell al pc via USB, la registrazione va a buon fine.
la funzione e' la seguente:


public void createFile() {
try {
FileConnection filecon = (FileConnection)
Connector.open("file:///E:/audio.wav");
// Always check whether the file or directory exists.
// Create the file if it doesn't exist.
if(!filecon.exists()) {
filecon.create();
filecon.setWritable(true);
}
filecon.close();
} catch(IOException ioe) {
System.out.println(ioe.getMessage());
}
}


2- il player non funziona.
Le ho provate tutte. eppure il file contiene qualcosa ma proprio non si sente nulla!!

anche in questo caso ecco il codice:

//PLAYER

public class PlayerMIDlet implements
CommandListener, PlayerListener, Runnable {
private Display display;
private Form form;
private TextField url;
private Command start = new Command("Play",
Command.SCREEN, 1);
private Command stop = new Command("Stop",
Command.SCREEN, 2);
private Player player;

public PlayerMIDlet() {

/* form = new Form("Demo Player");
url = new TextField("Enter URL:", "", 100,
TextField.URL);
form.append(url);
form.addCommand(start);
form.addCommand(stop);
form.setCommandListener(this);
display.setCurrent(form);*/
}

protected void startApp() {
try {
if(player != null && player.getState() ==
Player.PREFETCHED) {
player.start();
} else {
defplayer();
// display.setCurrent(form);
}
}
catch(MediaException me) {
reset();
}
}

protected void pauseApp() {
try {
if(player != null && player.getState() ==
Player.STARTED) {
player.stop();
} else {
defplayer();
}
}
catch(MediaException me) {
reset();
}
}

protected void destroyApp(
boolean unconditional) {
form = null;
try {
defplayer();
}
catch(MediaException me) {
}
}

public void playerUpdate(Player player,
String event, Object data) {
if(event == PlayerListener.END_OF_MEDIA) {
try {
defplayer();
}
catch(MediaException me) {
}
reset();
}
}

public void commandAction(Command c, Displayable d) {

}

public void start() {
Thread t = new Thread(this);
t.start();
}

// to prevent blocking, all communication should
// be in a thread
// and not in commandAction
public void run() {
play();
}

String getURL() {
return url.getString();
}

void play() {
try {
InputStream is =
getClass().getResourceAsStream("file:///E:/audio.wav");
Player player = Manager.createPlayer(is, "audio/X-wav");

player.prefetch();
player.start();
}
catch(Throwable t) {
reset();
}
}
/* versione ufficiale
void play(String url) {
try {
InputStream is =
getClass().getResourceAsStream(url);
Player player = Manager.createPlayer(is, "audio/X-wav");

player.prefetch();
player.start();
}
catch(Throwable t) {
reset();
}
}
*/
void defplayer() throws MediaException {
if (player != null) {
if(player.getState() == Player.STARTED) {
player.stop();
}
if(player.getState() == Player.PREFETCHED) {
player.deallocate();
}
if(player.getState() == Player.REALIZED ||
player.getState() == Player.UNREALIZED) {
player.close();
}
}
player = null;
}

void reset() {
player = null;
}

void stopPlayer() {
try {
defplayer();
}
catch(MediaException me) {
}
reset();
}}

se qualcuno potesse aiutarmi gliene sarei grato eternamente!! :D

^TiGeRShArK^
16-04-2007, 19:15
1) metti il codice tra i tag code altrimenti non si capisce una cippa :D

2) A volte a me capitava che dei file di immagini dovevano essere scritti nell'apposita directory dedicata a contenere le immagini.
Se provavo a scriverle in altri posti non fungeva :mbe:
Con altri tipi di file non ho mai avuto problemi del genere...quindi magari prova a scrivere il file nella cartella associata ai clip audio e vedi che succede :p

Dopo che metti i tag code vedo se riesco a darti un pò d'aiuto :p

Kl@
17-04-2007, 08:14
Intendi cosi? scusa ma sono nuovo del forum
un problema l'ho risolto, cioe' il primo!
ora devo solo riuscire a far funzionare il player per i file wav e poi ho finito!!:D