I am making a soundboard prank app. I can get everything else in the Program Working Fine except the playing audio part of the Program. I am using Java Sound and right now I am getting a Unsupportedaudiofileexception when i try to play the sound in a window.(I have the file set to a absolute file location(temporarily)) but there are also lots of more errors that make no sense.
(I have every 25 lines commented on and the ones that are referenced as errors on the console)
Code:
package com.dashboard.rickroll;
import java.awt.Color;
import java.awt.Container;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class RickRoll {
JFrame frame;
Container con;
JPanel buttonPanel;
JButton playButton;
JLabel lblRickRoll;
String rRSound; //line 25
ButtonHandler bHandler = new ButtonHandler();
RickRollSound rRS = new RickRollSound();
int playX = 110;
int playY = 120;
int playW = 60;
int playH = 60;
int rRlblX = 25;
int rRlblY = 10;
int rRlblW = 250;
int rRlblH = 60;
public static void main(String[] args) {
new RickRoll();
}
public RickRoll() {
frame = new JFrame();
frame.setSize(300,300);
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); //line 50
frame.getContentPane().setBackground(Color.white);
frame.setLayout(null);
frame.setLocationRelativeTo(null);
frame.setResizable(false);
frame.setAlwaysOnTop(false);
frame.setBackground(Color.WHITE);
con = frame.getContentPane();
frame.setVisible(true);
playButton = new JButton("Play");
playButton.setFocusPainted(false);
playButton.setBounds(playX, playY, playW, playH);
playButton.setFont(new Font("Times New Roman",Font.PLAIN, 12));
playButton.setBackground(Color.LIGHT_GRAY);
playButton.addActionListener(bHandler);
con.add(playButton);
lblRickRoll = new JLabel("RickRoll");
lblRickRoll.setBounds(rRlblX, rRlblY, rRlblW, rRlblH);
lblRickRoll.setFont(new Font("Times New Roman", Font.BOLD, 60));
con.add(lblRickRoll);
rRSound = "C:\\Users\\bduncan0856\\Desktop\\Sounds\\rickRoll.WAV";
}
//line 75
public class RickRollSound {
Clip clip;
public void setFile(String soundFileName) {
try {
File file = new File(soundFileName);
AudioInputStream rickRoll = AudioSystem.getAudioInputStream(file); //line 83
clip = AudioSystem.getClip();
clip.open(rickRoll);
}catch(Exception e) {
System.out.println("Error");
e.printStackTrace();
}
}
public void play() {
clip.setFramePosition(0);
clip.start();
}
}
public class ButtonHandler implements ActionListener{
public void actionPerformed(ActionEvent event) { //line 100
rRS.setFile(rRSound); //line 102
rRS.play();
}
}
public void setVisible(boolean b) {
frame.setVisible(true);
}
}
Console:
javax.sound.sampled.UnsupportedAudioFileException: could not get audio input stream from input file
Error
at javax.sound.sampled.AudioSystem.getAudioInputStream(Unknown Source)
at com.dashboard.rickroll.RickRoll$RickRollSound.setFile(RickRoll.java:83)
at com.dashboard.rickroll.RickRoll$ButtonHandler.actionPerformed(RickRoll.java:102)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$500(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at com.dashboard.rickroll.RickRoll$RickRollSound.play(RickRoll.java:94)
at com.dashboard.rickroll.RickRoll$ButtonHandler.actionPerformed(RickRoll.java:103)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$500(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)