Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > hi - help needed please

Reply
Thread Tools

hi - help needed please

 
 
Evil Monkey
Guest
Posts: n/a
 
      01-10-2004
Hi there, well my java game is nearly finished.

thanks for the advice the people on this board provided.

I have one more little question concerning sound..

i am using the following code for my applciation but getting no sound..

//amongst others...

import java.io.File;
import java.applet.Applet;
import java.applet.AudioClip;
import java.net.MalformedURLException;


AudioClip clip; //class variable

public void sound ()
{
File file = new File ("bomb.wav");

try
{
clip=Applet.newAudioClip(file.toURL());
}
catch(MalformedURLException mfe){}
}


//and elsewhere in my code..

clip.play();

can anyone see where I am going wrong ?? I simply want to play a small sound
when a graphical object hits another graphical object.

//it seems to be unable to find the file.. what syntax should i use to tell
it where to look?? e.g. h:\sound is my sounds source directory

any suggestions?? the speakers are up and working is there something obvious
im missing??


many thanks


 
Reply With Quote
 
 
 
 
Ryan Stewart
Guest
Posts: n/a
 
      01-10-2004
"Evil Monkey" <> wrote in message
news:riULb.184$...
> Hi there, well my java game is nearly finished.
>
> thanks for the advice the people on this board provided.
>
> I have one more little question concerning sound..
>
> i am using the following code for my applciation but getting no sound..
>
> //amongst others...
>
> import java.io.File;
> import java.applet.Applet;
> import java.applet.AudioClip;
> import java.net.MalformedURLException;
>
>
> AudioClip clip; //class variable
>
> public void sound ()
> {
> File file = new File ("bomb.wav");
>
> try
> {
> clip=Applet.newAudioClip(file.toURL());
> }
> catch(MalformedURLException mfe){}
> }
>
>
> //and elsewhere in my code..
>
> clip.play();
>
> can anyone see where I am going wrong ?? I simply want to play a small

sound
> when a graphical object hits another graphical object.
>
> //it seems to be unable to find the file.. what syntax should i use to

tell
> it where to look?? e.g. h:\sound is my sounds source directory
>
> any suggestions?? the speakers are up and working is there something

obvious
> im missing??
>
>
> many thanks


Are you sure file.toURL() is giving you what you want? Assuming you're
running this within an Applet, try:
new URL(getCodeBase() + "bomb.wav")


 
Reply With Quote
 
 
 
 
Alex Hunsley
Guest
Posts: n/a
 
      01-10-2004
Evil Monkey wrote:
> Hi there, well my java game is nearly finished.
>
> thanks for the advice the people on this board provided.
>
> I have one more little question concerning sound..
>
> i am using the following code for my applciation but getting no sound..
>
> //amongst others...
>
> import java.io.File;
> import java.applet.Applet;
> import java.applet.AudioClip;
> import java.net.MalformedURLException;
>
>
> AudioClip clip; //class variable
>
> public void sound ()
> {
> File file = new File ("bomb.wav");
>
> try
> {
> clip=Applet.newAudioClip(file.toURL());
> }
> catch(MalformedURLException mfe){}
> }
>
>
> //and elsewhere in my code..
>
> clip.play();
>
> can anyone see where I am going wrong ?? I simply want to play a small sound
> when a graphical object hits another graphical object.
>
> //it seems to be unable to find the file.. what syntax should i use to tell
> it where to look?? e.g. h:\sound is my sounds source directory
>
> any suggestions?? the speakers are up and working is there something obvious
> im missing??
>
>
> many thanks
>


Well, for a start, you're asking for head-scratching if you do this:

catch(MalformedURLException mfe){}

Why not actually indicate something if this exception is thrown? It may
be getting thrown and you'd have no idea.

aex




 
Reply With Quote
 
 
 
Reply

Thread Tools

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help Help Help Pentax S5i Help needed (Please) The Martian Digital Photography 14 06-20-2008 07:56 AM
Help Help Help Please Pentax S5i info needed The Martian Digital Photography 2 05-20-2008 07:00 AM
Help needed on this 857W config. Repost to be clearer what the problemsare and the help needed sparticle Cisco 3 08-30-2007 07:47 PM
HELP! HELP! PLEASE, PLEASE, PLEASE tpg comcntr Computer Support 11 02-15-2004 06:22 PM
please help... ...me learn C++ please please please :) KK C++ 2 10-14-2003 02:08 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57