I'm writing a program an I've encountered a problem when trying to play music. Not getting any errors when I compile (just a few warnings like "warning: AudioPlayer is internal proprietary API and may be removed in a future release
AudioPlayer MGP = AudioPlayer.player;")
But in my program when the music is supposed to be playing it displays my error message. the wave file is in the same directory as my program, and I first tried a wav that was 25MB, that didn't work then it tried a 12KB still didn't work. Can't really figure out while its not playing. here's some of the code
Code:import java.awt.*; import java.io.*; import sun.audio.*; import javax.swing.*; import java.awt.event.*; import java.awt.Color.*; import javax.swing.JFrame.*; import java.awt.EventQueue.*; private class button3Listener implements ActionListener { public void actionPerformed(ActionEvent e) { music(); } } public static void music() { AudioPlayer MGP = AudioPlayer.player; AudioStream BGM; AudioData MD; ContinuousAudioDataStream loop = null; try{ BGM = new AudioStream(new FileInputStream("bear.wav")); MD = BGM.getData(); loop = new ContinuousAudioDataStream(MD); }catch(IOException error){JOptionPane.showMessageDialog(null, "file not found");} MGP.start(loop); JOptionPane.showMessageDialog(null, "music should be playing"); }


Reply With Quote
Bookmarks