aspose file tools*
The moose likes Applets and the fly likes applets..audio sound Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Applets
Bookmark "applets..audio sound " Watch "applets..audio sound " New topic
Author

applets..audio sound

kieran pattni
Ranch Hand

Joined: Jan 19, 2004
Posts: 47
please can someone tell why this there is no sound ...applet works but no sound when buttons clicked..
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.net.URL;

public class SoundApplet extends Applet
implements ActionListener
{
private AudioClip sound;

public void init()
{
sound = getAudioClip(getCodeBase(), "beep.au");
Button b1 = new Button("Play");
Button b2 = new Button("Stop");
Button b3 = new Button("Loop");
add(b1);
add(b2);
add(b3);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
}

public void actionPerformed(ActionEvent ae)
{
if(ae.getActionCommand().equals("Play"))
sound.play();
if(ae.getActionCommand().equals("Stop"))
sound.stop();
if(ae.getActionCommand().equals("Loop"))
sound.loop();
}
}
Carlos Failde
Ranch Hand

Joined: Oct 20, 2000
Posts: 84
How are you running it? Is beep.au in the same directory as the applet?
I have tested your code and it works perfectly.
kieran pattni
Ranch Hand

Joined: Jan 19, 2004
Posts: 47
Yes the applet and the sound file is in the same directory..
Carlos Failde
Ranch Hand

Joined: Oct 20, 2000
Posts: 84
This is how I ran it:
I used a file SoundApplet.html:

Then ran:

Any exceptions may show up on the command line..
Hmm, beep.au isn't 0k in size is it? I mean it's a real sound file right?
[ February 29, 2004: Message edited by: Carlos Failde ]
Davy Kelly
Ranch Hand

Joined: Jan 12, 2004
Posts: 384
hey guys,
I have done the same course as kieran. the code is fine but with a made up HTML file, this does not get played, but in the appletviewer it does, why is this?
same code as kierans above, with a different sound file, in the same file as the source code.
but this is my HTML file

Davy


How simple does it have to be???
kieran pattni
Ranch Hand

Joined: Jan 19, 2004
Posts: 47
hello again...tried all things no result...it might be something to do with the windows media player i have...who knows...thanks for your help guys
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
It may have something to do with security settings and whether the Applet has permission to access the audio resource. I seem to recall that security settings on Applets run through the appletviewer were a bit more lax than on Applets run through a web browser. But I don't remember Applets in complete detail.
Moving this to the Applets forum...


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: applets..audio sound