×

Discussion Board

Results 1 to 4 of 4
  1. #1
    Registered User
    Join Date
    Oct 2007
    Posts
    7

    Ploblems when trying to play audio

    Hi!I'm starting with J2ME and audio and i got ploblems when i try to play a sound in the Emulator and in my Nokia cell. Otherwise, when i play it with the Java Wireless toolkit of Sun Microsystems it works perfectly. I don't know if i need something special to play audio on a Nokia cell or it's enough with a normal J2ME application...

    Thanks in advance

    Miguel

  2. #2
    Nokia Developer Champion
    Join Date
    Nov 2007
    Location
    Rome, Italy
    Posts
    2,405

    Re: Ploblems when trying to play audio

    Which audio format are you trying to play? Are you getting an Exception on Nokia phones/emulator? Try posting the code you use within your application, so it'll be easier to help you.

    Pit

  3. #3
    Registered User
    Join Date
    Oct 2007
    Posts
    7

    Re: Ploblems when trying to play audio

    I try to play a wav file, a tone and a melody of tones. When i run it on both,the emulator and my phone, it does nothing, but it runs. I post the code so that you can take a look. Thanks again.


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

    public class Sonido extends MIDlet implements CommandListener {

    private Display display;
    private Form formulario;
    private Command exit;
    private Command wav, nota, secuenciaa;

    public Sonido() {
    display = Display.getDisplay(this);
    exit = new Command("Salir", Command.EXIT, 1);
    wav = new Command("WAV", Command.SCREEN, 2);
    nota = new Command("Nota", Command.SCREEN, 2);
    secuenciaa = new Command("Secuenciaa", Command.SCREEN, 2);
    formulario = new Form("Reproducir.");
    formulario.addCommand(exit);
    formulario.addCommand(wav);
    formulario.addCommand(nota);
    formulario.addCommand(secuenciaa);
    formulario.setCommandListener(this);
    }

    public void startApp() {
    display.setCurrent(formulario);
    }

    public void pauseApp() {
    }

    public void destroyApp(boolean unconditional) {
    }

    public void commandAction(Command c, Displayable s) {
    if (c == exit) {
    destroyApp(false);
    notifyDestroyed();
    } else {
    if (c == wav) {
    playWav();
    }
    if (c == nota) {
    playNota();
    }
    if (c == secuenciaa) {
    playSecuencia();
    }
    }
    }

    public void playWav() {
    try {
    // Abrir corriente de datos del archivo de sonido
    InputStream in = getClass().getResourceAsStream("./explosion.wav");
    Player p = Manager.createPlayer(in, "audio/x-wav");
    // comenzar reproducción
    p.start();
    } catch (Exception e) {
    e.printStackTrace();
    Alert alr = new Alert("Error", "No se pudo reproducir el sonido", null, AlertType.ERROR);
    alr.setTimeout(Alert.FOREVER);
    display.setCurrent(alr, formulario);
    }
    }

    public void playNota() {
    try {
    // reproducir nota
    Manager.playTone(ToneControl.C4, 100, 80);
    } catch (Exception e) {
    }
    }

    public void playSecuencia() {
    byte tempo = 30;
    byte d = 8;
    // Creamos las notas a partir del Do central
    byte C4 = ToneControl.C4;
    byte D4 = (byte) (C4 + 2);
    byte E4 = (byte) (C4 + 4);
    byte F4 = (byte) (C4 + 5);
    byte G4 = (byte) (C4 + 7);
    byte silencio = ToneControl.SILENCE;
    byte[] secuencia = {
    ToneControl.VERSION, 1,
    ToneControl.TEMPO, tempo,
    // comienzo del bloque 0
    ToneControl.BLOCK_START, 0,
    // notas del bloque 0
    C4, d, F4, d, F4, d, C4, d, F4, d, F4, d, C4, d, F4, d,
    // fin del bloque 0
    ToneControl.BLOCK_END, 0,
    // inicio del bloque 1
    ToneControl.BLOCK_START, 1,
    // notas del bloque 1
    C4, d, E4, d, E4, d, C4, d, E4, d, E4, d, C4, d, E4, d,
    // fin del bloque 1
    ToneControl.BLOCK_END, 1,
    // reproducir bloque 0
    ToneControl.PLAY_BLOCK, 0,
    // reproducir bloque 1
    ToneControl.PLAY_BLOCK, 1,
    // reproducir bloque 0
    ToneControl.PLAY_BLOCK, 0,
    };
    try {
    Player p = Manager.createPlayer(Manager.TONE_DEVICE_LOCATOR);
    p.realize();
    ToneControl c = (ToneControl) p.getControl("ToneControl");
    c.setSequence(secuencia);
    p.start();
    } catch (IOException ioe) {
    } catch (MediaException me) {
    }
    }
    }

  4. #4
    Registered User
    Join Date
    Oct 2007
    Posts
    7

    Re: Ploblems when trying to play audio

    Please help!

Similar Threads

  1. Recording in Amr Format
    By losym in forum Symbian Media (Closed)
    Replies: 12
    Last Post: 2009-03-26, 06:41
  2. To play raw audio data file
    By pawans in forum Symbian Tools & SDKs
    Replies: 2
    Last Post: 2008-12-11, 11:38
  3. Using Audio Proxy Server to play only (not play and record)
    By rob_savageminds in forum Symbian Media (Closed)
    Replies: 7
    Last Post: 2007-09-04, 12:11
  4. Half Duplex Audio Streaming
    By subhrajyotisaha in forum Symbian Media (Closed)
    Replies: 0
    Last Post: 2006-05-25, 04:39
  5. Load and play audio file
    By itenel in forum Symbian C++
    Replies: 4
    Last Post: 2004-05-17, 07:20

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •