Necesito ayuda

Imagen de iggc80
0 puntos

Necesito ayuda con un programa para capturar audio (o voz) para un celular en J2ME, tengo entendido que los códigos deben ejecutarse sobre el dispositivo ya que el emulador de Java no lo permite (si estoy mal corriganme), pero aun asi no me esta corriendo bien, me aparece la siguiente excepción:

SoundCaptureMidlet, Hello.SoundCaptureMidlet
Exception: java.lang.ClassNotFoundException:
Hello/SoundCaptureMidlet

El código es el siguiente:

package hello;

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

public class PlayerThread extends Thread implements PlayerListener{

InputStream is =null;
String type = null;
Player player=null;
long startTime = 0;
long startedTime=0;
long stopTime=0;
String fileName=null;

public PlayerThread(InputStream is, String type ) {
this.is = is;
this.type=type;
}
public PlayerThread( String filename) {
this.fileName=filename;
}

public void run()
{
try{
startTime=System.currentTimeMillis()/1000;
// creating the player depending on which constructor has been used
// if the constructor that takes a file name has been used the progressive download
// functionality will be used.

if(fileName==null)
player = Manager.createPlayer(is, type );
else
player = Manager.createPlayer(fileName);
// registering the playerthread as a PlayerListener
player.addPlayerListener(this);

// Allocating the resources for the audio data
player.realize();
// start the playback
player.start();

}catch(Exception e){System.out.println(e.toString());}

}

public void playerUpdate(Player player,java.lang.String event,java.lang.Object eventData)
{
if (event.compareTo(PlayerListener.STARTED)==0 ) {
startedTime=System.currentTimeMillis()/1000;
System.out.println("player creation Time="+(startedTime-startTime));
}

if (event.compareTo(PlayerListener.END_OF_MEDIA)==0 ) {
stopTime=System.currentTimeMillis()/1000;
System.out.println("playTime="+(stopTime-startTime));
// When the media has been played we close the player
player.close();
}
}
}

__________________________________

package hello;

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

import java.io.*;

public class SoundCaptureMIdlet extends MIDlet implements javax.microedition.lcdui.CommandListener, PlayerListener {
ByteArrayOutputStream outputStream =null;
byte[] byteArray = null;
String locator= "capture://audio";
Player player =null;
Form form;
TextField tb = null;
Command recCommand, stopRecCommand, playCommand,exitCommand;
Display display=null;

RecordControl rc=null;
ChoiceGroup cg;
/** Creates a new instance of HelloMidlet */
public SoundCaptureMIdlet () {

cg= new ChoiceGroup ("Record to", ChoiceGroup.EXCLUSIVE);
cg.append("file",null);
cg.append("byteArray", null);
cg.setSelectedIndex(1, true);
form = new Form("Audio Capture");

recCommand = new Command("record", Command.OK, 1);
stopRecCommand = new Command("stop record", Command.OK, 1);
playCommand = new Command("Play", Command.SCREEN, 2);
exitCommand = new Command("Exit", Command.SCREEN, 2);

tb = new TextField("SoundCapture", "info", 256, TextField.UNEDITABLE) ;
form.addCommand(recCommand);
form.addCommand(playCommand);
form.addCommand(exitCommand);
form.setCommandListener(this);

form.append(tb);
form.append(cg);

}

// --- This section is auto-generated by NetBeans IDE. Do not modify or you may lose your changes.//
/**
* This method initializes UI of the application.
*/
private void initialize() {
}

// --- This is the end of auto-generated section.//

public void startApp() {
if(display==null)
display=Display.getDisplay(this);
display.setCurrent(form);
initialize();
}

public void pauseApp() {
}

public void destroyApp(boolean unconditional) {
}

public void commandAction(Command c, Displayable s) {

// Making a boolean vector to get the options from the choicegroup
boolean flags[] = new boolean[2];
flags[0]=false;
flags[1]=false;

cg.getSelectedFlags(flags);
if (c == recCommand) // start the recording
{
System.out.println("recCommand");
tb.setString("Recorder started:");
// Changing the recCommand with the stopCommand
form.removeCommand(recCommand);
form.addCommand(stopRecCommand);

try{
// creating the player from the file url enabling progressive download
player = Manager.createPlayer(locator);
// adding playerListenter
player.addPlayerListener(this);
// allocating the resources from the microphone
player.realize();
// Getting the ReocrdControll so we can record the output from the player
rc = (RecordControl)player.getControl("RecordControl");
}
catch(Exception er){tb.setString(er.toString());}

if(flags[0]) // If we are saving the recorde audio to file
{
try{
// setting the record location to the file
rc.setRecordLocation("file:///c:/other/audio.amr");
// start recording
rc.startRecord();
// start to play the sound from the microphone
player.start();
}catch(Exception t){tb.setString(t.toString());}
}
else // If we are saving to an OutputStream
{
outputStream = null;
outputStream = new ByteArrayOutputStream();

if(rc==null)
System.out.println("rc==null");
// setting the record location to the outputstream
rc.setRecordStream(outputStream);

try{
// start recording
rc.startRecord();
// start to play the sound from the microphone
player.start();

}
catch(Exception e){tb.setString(e.toString());}

}

}
else if (c == stopRecCommand) // Stop the recording
{
System.out.println("StoprecCommand");
// Changing the stopCommand with recCommand
form.removeCommand(stopRecCommand);
form.addCommand(recCommand);
try{

// stop recording
rc.commit();
// and stop the playback from the microphone
player.close();

tb.setString("Recorder to byteArray stopped:");
}
catch(Exception e){tb.setString(e.toString());}
}
else if (c == playCommand) // start the playback of the recorded audio
{

if(flags[0]) // to File
{
System.out.println("play from File");
// creating and starting the playback thread
new PlayerThread("file:///c:/other/audio.amr").start();

}
else // to outputStream
{
System.out.println("play from ByteArrayInputStream");
if(outputStream==null)
return;
// getting the ByteArray from the ByteArrayOutputStream
byteArray = outputStream.toByteArray();
// Creating and starting the playback thread
new PlayerThread(new ByteArrayInputStream(byteArray), "audio/amr" ).start();

}
tb.setString("Playing ");
}
else if (c == exitCommand)
{
notifyDestroyed();
}

}

public void playerUpdate(Player player,java.lang.String event,java.lang.Object eventData)
{
System.out.println("playerUpdate event="+event);

}

}

En serio necesito hacer que funcione, es para un proyecto de la escuela, también no se si corra en cualquier celular.

Imagen de Anónimo
+1
0
-1

Comprueba que referencias bien a esa clase,pues no la reconoce.

P.D:Por favor aprendamos a leer los mensajes de error y a obrar en consecuencia

+1
0
-1
Imagen de Goyo
+1
0
-1

De momento tienes dos formas de escribir lo que probablemente es lo mismo:

SoundCaptureMidlet
SoundCaptureMIdlet

A ver si va a ser eso.

+1
0
-1
Imagen de Anónimo
+1
0
-1

Oye muchas gracias pero lo que tenía mal era el jad. De todos modos sirvio para darme cuenta de algunos detalles.

+1
0
-1