×

Discussion Board

Results 1 to 7 of 7

Thread: Playing WAVs

  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    17

    Playing WAVs

    I can't find any sample code of how to play wav files on Series 60.
    Can anyone point me in the right direction ?

  2. #2
    Super Contributor
    Join Date
    Mar 2003
    Location
    Israel
    Posts
    2,280
    Creating the sound:
    Code:
          InputStream tune = this.getClass().getResourceAsStream("/res/dice-2.wav"); // I have the wav packaged in the jar
          byte[] diceWAV = new byte[8000];
          tune.read(diceWAV,0,diceWAV.length);
          soundDice = new Sound(diceWAV,Sound.FORMAT_WAV);
          soundDice.init(diceWAV,Sound.FORMAT_WAV);
    And then playing the sound is a simple matter of calling the Sound.play() method whenever you need it.

  3. #3
    Registered User
    Join Date
    Mar 2003
    Posts
    17
    Which package is InputStream in ?
    I can't find it.

  4. #4
    Registered User
    Join Date
    Mar 2003
    Posts
    2
    InputStream is found in java.io

  5. #5
    Registered User
    Join Date
    Apr 2003
    Posts
    2
    i can't get the code you gave to work sir.

    here is what i did...

    code:
    ___________________________________________________

    import java.io.IOException;
    import javax.microedition.lcdui.*;
    import java.lang.*;
    import javax.microedition.midlet.*;
    import javax.microedition.rms.*;

    import java.io.*;

    import com.nokia.mid.sound.Sound;

    public class GameFullCanvas extends Canvas
    {
    Sound player=null;
    int vol=50;
    boolean go=false;

    public GameFullCanvas()
    {
    repaint();
    }



    public void paint(Graphics g) {
    //clear screen
    g.setColor(0xffffff);
    g.fillRect(0,0,getWidth(),getHeight());
    g.setColor(0);

    g.drawString("vol: "+vol,5,30,g.TOP|g.LEFT);

    if(player==null)
    g.drawString("not paying",5,45,g.TOP|g.LEFT);
    else
    g.drawString("playing",5,45,g.TOP|g.LEFT);
    }


    public void keyPressed(int code)
    {
    int key1=getGameAction(code);
    if(key1==Canvas.UP)
    if(vol!=100)
    vol+=10;
    if(key1==Canvas.DOWN)
    if(vol!=0)
    vol-=10;
    if(key1==Canvas.FIRE)
    stop();
    if(key1==Canvas.LEFT)
    play(go);
    if(key1==Canvas.RIGHT)
    go=!go;
    }

    public void keyReleased(int code)
    {
    repaint();
    }
    public void play(boolean t)
    {


    try{

    InputStream tune = this.getClass().getResourceAsStream("lou.wav");

    byte[] data = new byte[3000];

    tune.read(data,0,data.length);
    System.out.println(data);
    player = new Sound(data,Sound.FORMAT_WAV);
    if(player == null)
    System.out.println("HELLO");
    player.play(1);
    System.out.println(Sound.SOUND_PLAYING);

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

    public void stop()
    {
    try{
    player.stop();
    player=null;
    }catch(Exception e){}
    }
    }

  6. #6
    Regular Contributor
    Join Date
    Mar 2003
    Location
    Austria
    Posts
    86
    Hi!

    I have no experiences with sound, but try to load the resource as "/lou.wav". Perhaps it helps.

    McMc

  7. #7
    Super Contributor
    Join Date
    Mar 2003
    Location
    Israel
    Posts
    2,280
    It also looks like you're missing the call to player.init() after calling the constructor.

    shmoove

Posting Permissions

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