| Reply | « Previous Thread | Next Thread » |
|
I can't find any sample code of how to play wav files on Series 60.
Can anyone point me in the right direction ? |
| neilcoxhead |
| View Public Profile |
| Find all posts by neilcoxhead |
|
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);
|
|
Which package is InputStream in ?
I can't find it. |
| neilcoxhead |
| View Public Profile |
| Find all posts by neilcoxhead |
|
InputStream is found in java.io
|
|
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){} } } |
|
Hi!
I have no experiences with sound, but try to load the resource as "/lou.wav". Perhaps it helps. McMc |
|
It also looks like you're missing the call to player.init() after calling the constructor.
shmoove |
| Reply | « Previous Thread | Next Thread » |
| Thread Tools | Search this Thread |
|---|---|