import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.net.*;
import javax.swing.*;
public class Audioapp {
public Audioapp() {
}
private static void createAndShowGui() {
JFrame window = new JFrame();
window.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
window.setSize(400, 300);
window.setLocationRelativeTo(null);
JButton btPlay = new JButton("Play");
window.add(btPlay, BorderLayout.PAGE_START);
window.setVisible(true);
btPlay.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent e) {
Sound testsong = new Sound("song.mid");
testsong.playSoundOnce();
}
});
}
public static void main(final String... args) {
Runnable gui = new Runnable() {
public void run() {
createAndShowGui();
}
};
//GUI must start on EventDispatchThread:
SwingUtilities.invokeLater(gui);
}
}
class Sound {
private AudioClip song; // Sound player
private URL songPath; // Sound path
Sound(final String filename) {
songPath = getClass().getResource(filename); // Get the Sound URL
song = Applet.newAudioClip(songPath); // Load the Sound
}
public void playSound() {
song.loop(); // Play
}
public void stopSound() {
song.stop(); // Stop
}
public void playSoundOnce() {
song.play(); // Play only once
}
}
package akkuladestand;
import java.applet.Applet;
import java.applet.AudioClip;
import java.io.File;
import java.net.MalformedURLException;
public class TestSound
{
public static void main(String[] args) throws MalformedURLException
{
File a = new File( "uups.wav" );
System.out.println(a.toURL());
AudioClip sound;
sound = Applet.newAudioClip( a.toURL() );
sound.play();
try
{
Thread.sleep( 10000 );
} catch (InterruptedException e)
{
// TODO Automatisch erstellter Catch-Block
e.printStackTrace();
}
}
}
System.out.println(a.toURL);
Baut man in sein Programm einen Korrekturmechanismus
Ich weiß nicht... JMF ist doch schon seit längerem wie tot?