You Are Here:

Community: Developer Discussion Boards

#1 Old Playing WAVs - 2003-04-07, 23:29

Join Date: Mar 2003
Posts: 17
neilcoxhead
Offline
Registered User
I can't find any sample code of how to play wav files on Series 60.
Can anyone point me in the right direction ?
Reply With Quote

#2 Old 2003-04-08, 09:20

Join Date: Mar 2003
Posts: 2,280
Location: Israel
shmoove
Offline
Forum Nokia Champion
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.
Reply With Quote

#3 Old 2003-04-08, 10:09

Join Date: Mar 2003
Posts: 17
neilcoxhead
Offline
Registered User
Which package is InputStream in ?
I can't find it.
Reply With Quote

#4 Old 2003-04-08, 17:43

Join Date: Mar 2003
Posts: 2
noppe
Offline
Registered User
InputStream is found in java.io
Reply With Quote

#5 Old 2003-05-06, 07:55

Join Date: Apr 2003
Posts: 2
mat_sze
Offline
Registered User
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){}
}
}
Reply With Quote

#6 Old 2003-05-12, 16:52

Join Date: Mar 2003
Posts: 86
Location: Austria
mcmcdonald
Offline
Regular Contributor
Hi!

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

McMc
Reply With Quote

#7 Old 2003-05-14, 09:38

Join Date: Mar 2003
Posts: 2,280
Location: Israel
shmoove
Offline
Forum Nokia Champion
It also looks like you're missing the call to player.init() after calling the constructor.

shmoove
Reply With Quote
Reply « Previous Thread | Next Thread »
Display Modes
Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules

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

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Forum Jump

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia 
RDF Facets: qdcZidentifierQSxhttpE3aE2fE2fdiscussionE2eforumE2enokiaE2ecomhttpE3aE2fE2fdiscussionE2eforumE2enokiaE2ecomE2fforumE2fshowthreadE2ephpE3ftE3d18645X qdcZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qdcZtypeQUqfntypeZCommunityContentQ qdcZtypeQUqfntypeZE44iscussionQ qdcZtypeQUqfntypeZE44iscussionContentQ qdcZtypeQUqfntypeZE52esourceQ qdcZtypeQUqfntypeZWebpageQ qdcZtypeQUqmarsZManagedE52esourceQ qdcZtypeQUqwebZInformationE52esourceQ qdcZtypeQUqwebZPageQ qdcZtypeQUqwebZE52esourceQ qdcZtypeQUqrdfsZE52esourceQ qfnZtopicQUqfnTopicZentertainmentQ qfnZtopicQUqfnTopicZj2meQ qfnZtopicQUqfnTopicZjavaQ qfnZtopicQUqfnTopicZmediaQ qfnZtypeQUqfntypeZCommunityContentQ qfnZtypeQUqfntypeZE44iscussionQ qfnZtypeQUqfntypeZE44iscussionContentQ qfnZtypeQUqfntypeZE52esourceQ qfnZtypeQUqfntypeZWebpageQ qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX qrdfZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qrdfZtypeQUqfntypeZCommunityContentQ qrdfZtypeQUqfntypeZE44iscussionQ qrdfZtypeQUqfntypeZE44iscussionContentQ qrdfZtypeQUqfntypeZE52esourceQ qrdfZtypeQUqfntypeZWebpageQ qrdfZtypeQUqmarsZManagedE52esourceQ qrdfZtypeQUqwebZInformationE52esourceQ qrdfZtypeQUqwebZPageQ qrdfZtypeQUqwebZE52esourceQ qrdfZtypeQUqrdfsZE52esourceQ