Solved: Simple java issue: Want to play sound on button press

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Inglonias

Thread Starter
Joined
Nov 13, 2009
Messages
82
Wow. I feel like an utter noob around here.

I just want a program I can run in case I do something cool to play a little victory tune. And preferably, it can play MP3 files. I'm good with midi, but MP3 would be nice. Code is below. It won't run. Errors at the InputStream part.

Code:
package victorytune;

import java.applet.AudioClip;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.FileInputStream;
import java.io.InputStream;
import javax.swing.JApplet;
import javax.swing.JButton;
import sun.audio.AudioPlayer;
import sun.audio.AudioStream;

public class VictoryTune extends JApplet implements ActionListener
{
Container con = getContentPane();
JButton playSound = new JButton("That was awesome!");

public void init()
    {
    con.add(playSound);
    con.setLayout(new FlowLayout());
    playSound.addActionListener(this);
    }
public void actionPerformed(ActionEvent e)
    {
    InputStream in = new FileInputStream("victory.midi");
    AudioStream as = new AudioStream(in);
    AudioPlayer.player.start(as);
    }
}
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Members online

Top