• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

applets..audio sound  RSS feed

 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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();
}
}
 
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes the applet and the sound file is in the same directory..
 
Carlos Failde
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 384
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
kieran pattni
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!