Java application to play a sound?

Category: Java SE
 
sihongqingnian
2009-12-14 06:13:25

Sponsored Links
Novice just beginning to learn, play sound files on the book's examples are Applet program, now I want the application to play a sound file, how should I do? Assuming sound files and source files are msg.wav in the same directory, I first used AudioClip defines an object, the next step how to do it?

Sponsored Links

sdfssg
2009-12-14 06:16:02
You can see: 9080/bh/forum/view.jsp? id = 0000000067 & ZT = 0000000008
this station on a more detailed explanation
sales56
2009-12-14 06:22:21
above That program is the applet ah, there is no main function, you write a html page
<html> <head> </head>
<body>
<applet code = PlayMedia.class width = 300 height = 300>
</applet>
</body>
</html>
maiklove_520
2009-12-14 06:41:23
This is my Not long ago learned. You can refer to

import java.awt. *;
Import java.awt.event. *;
Import java.applet.Applet;
import java.applet.AudioClip;

public class PlayMedia extends Applet implements ActionListener
{
AudioClip audio;
Button btnPlay;
Button btnStop;
public void init ()
; {
btnPlay = new Button ("Play");
btnStop = new Button ("Stop");
add (btnPlay);
add (btnStop );
btnPlay.addActionListener (this);
btnStop.addActionListener (this);
try
{
audio = getAudioClip (getDocumentBase (), "1.au");
}
; catch (Exception e)
{
System. out.println (e.toString ());
}
}
public ; void actionPerformed (ActionEvent e)
{
if (e.getSource () == btnPlay)
{
try
{
audio.play ();
}
catch (Exception err)
{
System . out.println (err.toString ());
}
;}
if (e.getSource () == btnStop)
{
try
{
audio.stop ();
;}
catch (Exception err)
; {
System.out.println (err.toString ());
}
}
}
}
tattocau
2009-12-14 06:43:28
this program what kind of environment you want to run, I use javac PlayMedia.java compilation is right, but when it occurs with java PlayMedia "Exception in thread "main" java.lang.NoSuchMethodError: main ".
how to solve ah?
xuyunfei
2009-12-14 06:48:04
AudioClip class
lijietan
2009-12-14 06:58:50
ding a
zhang5218898
2009-12-14 07:11:10
just that problem has been solved, thank you upstairs.

But how pressed the PLAY button but no sound it?
jngame
2009-12-14 07:26:13
Have you ever 1.au this sound file
Domain and server ip had changed since 8/23/2013. Suspend the user registration and posts for program maintenance.