Bom dia a todos, eu gostaria de desenvolver um mp3 player e um wav player para celular usando JME.
Só que eu executo dá erros:
Segue abaixo o código do wav player:
Obs: estou tentando executar o .wav a partir de um arquivo .jar. Uma coisa, tem maneira certa de criar o .jar ou posso usar o winrar?
package player;
import java.io.InputStream;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.StringItem;
import javax.microedition.media.Manager;
import javax.microedition.media.Player;
import javax.microedition.midlet.MIDlet;
public class WavPlayer extends MIDlet implements CommandListener {
public WavPlayer() {
display = Display.getDisplay(this);
// criamos o comando sair
exit = new Command("Sair", Command.EXIT, 2);
// criamos a tela principal
screen = new Form ("Player");
screen.append(new StringItem("","Informalções do Player:\n"));
{ // ---- memório total e livre ----
Runtime runtime = Runtime.getRuntime();
memTotal = Long.toString(runtime.totalMemory());
memLivre = Long.toString(runtime.freeMemory());
screen.append(new StringItem("","Memória Total: " + memTotal + "b\n"));
screen.append(new StringItem("","Memória Livre: " + memLivre + "b\n\n"));
}
{ // player
try {
audio = getClass().getResourceAsStream("Tarzan.wav");
player = Manager.createPlayer(audio, "audio/X-wav");
player.start();
}
catch(Exception e) {
screen.append(new StringItem("","Erro:: " + e + "b\n"));
System.err.println("Erro: " + e);
}
}
screen.addCommand(exit);
screen.setCommandListener(this);
}
protected void startApp() { // método de iniciação da Aplicação
display.setCurrent(screen);
}
protected void pauseApp() {
}
protected void destroyApp(boolean bool) {
}
public void commandAction(Command cmd, Displayable disp) {
if (cmd == exit) {
destroyApp(false);
notifyDestroyed();
}
}
// ---- variáveis ----
private Display display;
private Form screen;
private Command exit;
private String memTotal, memLivre;
private Player player;
private InputStream audio;
}
o erro é o seguinte:
Running with storage root MediaControlSkin
Erro: java.lang.IllegalArgumentException
Execution completed.
736479 bytecodes executed
11 thread switches
740 classes in the system (including system classes)
3801 dynamic objects allocated (108916 bytes)
2 garbage collections (84752 bytes collected)
Segue abaixo o código do mp3player:
Obs: eu queria ler o .mp3 local, armazenar as músicas no celular e carrega-las.
package player;
import java.io.InputStream;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.StringItem;
import javax.microedition.media.Manager;
import javax.microedition.media.Player;
import javax.microedition.media.control.VolumeControl;
import javax.microedition.midlet.MIDlet;
public class Mp3Player extends MIDlet implements CommandListener {
public Mp3Player() {
display = Display.getDisplay(this);
// criamos o comando sair
exit = new Command("Sair", Command.EXIT, 2);
// criamos a tela principal
screen = new Form ("Player");
screen.append(new StringItem("","Informalções do Player:\n"));
{ // ---- memório total e livre ----
Runtime runtime = Runtime.getRuntime();
memTotal = Long.toString(runtime.totalMemory());
memLivre = Long.toString(runtime.freeMemory());
screen.append(new StringItem("","Memória Total: " + memTotal + "b\n"));
screen.append(new StringItem("","Memória Livre: " + memLivre + "b\n\n"));
}
{ // player
try {
audio = getClass().getResourceAsStream("/your.mp3");
player = Manager.createPlayer(audio,"audio/mpeg");
player.realize();
// get volume control for player and set volume to max
vc = (VolumeControl) player.getControl("VolumeControl");
if(vc != null)
{
vc.setLevel(100);
}
player.prefetch();
player.start();
}
catch(Exception e) {
screen.append(new StringItem("","Erro:: " + e + "b\n"));
System.err.println("Erro: " + e);
}
}
screen.addCommand(exit);
screen.setCommandListener(this);
}
protected void startApp() { // método de iniciação da Aplicação
display.setCurrent(screen);
}
protected void pauseApp() {
}
protected void destroyApp(boolean bool) {
}
public void commandAction(Command cmd, Displayable disp) {
if (cmd == exit) {
destroyApp(false);
notifyDestroyed();
}
}
// ---- variáveis ----
private Display display;
private Form screen;
private Command exit;
private String memTotal, memLivre;
private Player player;
private InputStream audio;
private VolumeControl vc;
}
O erro é:
Running with storage root MediaControlSkin
Erro: java.lang.IllegalArgumentException
Execution completed.
735929 bytecodes executed
11 thread switches
740 classes in the system (including system classes)
3801 dynamic objects allocated (109044 bytes)
3 garbage collections (85856 bytes collected)
Estou usando o Eclipse.
Muito Obrigado desde já
FábioBom dia a todos, eu gostaria de desenvolver um mp3 player e um wav player para celular usando JME.
Só que eu executo dá erros:
Segue abaixo o código do wav player:
Obs: estou tentando executar o .wav a partir de um arquivo .jar. Uma coisa, tem maneira certa de criar o .jar ou posso usar o winrar?
package player;
import java.io.InputStream;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.StringItem;
import javax.microedition.media.Manager;
import javax.microedition.media.Player;
import javax.microedition.midlet.MIDlet;
public class WavPlayer extends MIDlet implements CommandListener {
public WavPlayer() {
display = Display.getDisplay(this);
// criamos o comando sair
exit = new Command("Sair", Command.EXIT, 2);
// criamos a tela principal
screen = new Form ("Player");
screen.append(new StringItem("","Informalções do Player:\n"));
{ // ---- memório total e livre ----
Runtime runtime = Runtime.getRuntime();
memTotal = Long.toString(runtime.totalMemory());
memLivre = Long.toString(runtime.freeMemory());
screen.append(new StringItem("","Memória Total: " + memTotal + "b\n"));
screen.append(new StringItem("","Memória Livre: " + memLivre + "b\n\n"));
}
{ // player
try {
audio = getClass().getResourceAsStream("Tarzan.wav");
player = Manager.createPlayer(audio, "audio/X-wav");
player.start();
}
catch(Exception e) {
screen.append(new StringItem("","Erro:: " + e + "b\n"));
System.err.println("Erro: " + e);
}
}
screen.addCommand(exit);
screen.setCommandListener(this);
}
protected void startApp() { // método de iniciação da Aplicação
display.setCurrent(screen);
}
protected void pauseApp() {
}
protected void destroyApp(boolean bool) {
}
public void commandAction(Command cmd, Displayable disp) {
if (cmd == exit) {
destroyApp(false);
notifyDestroyed();
}
}
// ---- variáveis ----
private Display display;
private Form screen;
private Command exit;
private String memTotal, memLivre;
private Player player;
private InputStream audio;
}
o erro é o seguinte:
Running with storage root MediaControlSkin
Erro: java.lang.IllegalArgumentException
Execution completed.
736479 bytecodes executed
11 thread switches
740 classes in the system (including system classes)
3801 dynamic objects allocated (108916 bytes)
2 garbage collections (84752 bytes collected)
Segue abaixo o código do mp3player:
Obs: eu queria ler o .mp3 local, armazenar as músicas no celular e carrega-las.
package player;
import java.io.InputStream;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.StringItem;
import javax.microedition.media.Manager;
import javax.microedition.media.Player;
import javax.microedition.media.control.VolumeControl;
import javax.microedition.midlet.MIDlet;
public class Mp3Player extends MIDlet implements CommandListener {
public Mp3Player() {
display = Display.getDisplay(this);
// criamos o comando sair
exit = new Command("Sair", Command.EXIT, 2);
// criamos a tela principal
screen = new Form ("Player");
screen.append(new StringItem("","Informalções do Player:\n"));
{ // ---- memório total e livre ----
Runtime runtime = Runtime.getRuntime();
memTotal = Long.toString(runtime.totalMemory());
memLivre = Long.toString(runtime.freeMemory());
screen.append(new StringItem("","Memória Total: " + memTotal + "b\n"));
screen.append(new StringItem("","Memória Livre: " + memLivre + "b\n\n"));
}
{ // player
try {
audio = getClass().getResourceAsStream("/your.mp3");
player = Manager.createPlayer(audio,"audio/mpeg");
player.realize();
// get volume control for player and set volume to max
vc = (VolumeControl) player.getControl("VolumeControl");
if(vc != null)
{
vc.setLevel(100);
}
player.prefetch();
player.start();
}
catch(Exception e) {
screen.append(new StringItem("","Erro:: " + e + "b\n"));
System.err.println("Erro: " + e);
}
}
screen.addCommand(exit);
screen.setCommandListener(this);
}
protected void startApp() { // método de iniciação da Aplicação
display.setCurrent(screen);
}
protected void pauseApp() {
}
protected void destroyApp(boolean bool) {
}
public void commandAction(Command cmd, Displayable disp) {
if (cmd == exit) {
destroyApp(false);
notifyDestroyed();
}
}
// ---- variáveis ----
private Display display;
private Form screen;
private Command exit;
private String memTotal, memLivre;
private Player player;
private InputStream audio;
private VolumeControl vc;
}
O erro é:
Running with storage root MediaControlSkin
Erro: java.lang.IllegalArgumentException
Execution completed.
735929 bytecodes executed
11 thread switches
740 classes in the system (including system classes)
3801 dynamic objects allocated (109044 bytes)
3 garbage collections (85856 bytes collected)
Estou usando o Eclipse.
Muito Obrigado desde já
Fábio