Results 1 to 2 of 2
Thread: playing music in java
- 03-08-2013, 11:45 AM #1
Member
- Join Date
- Feb 2013
- Posts
- 10
- Rep Power
- 0
playing music in java
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
Java 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"); }
- 03-08-2013, 12:09 PM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,448
- Rep Power
- 16
Re: playing music in java
You should be using javax.sound, not the internal sun.audio classes (hence the warning).
Here's a link to the java sound resources site, and to a simple audio playback class that describes what it's doing.Please do not ask for code as refusal often offends.
Similar Threads
-
How to Put Music Into Java?
By DRLC in forum New To JavaReplies: 1Last Post: 09-07-2012, 01:10 AM -
playing music
By snowhite in forum Java ServletReplies: 5Last Post: 05-06-2012, 01:41 PM -
Java, Playing Music?
By Alerhau in forum New To JavaReplies: 3Last Post: 08-18-2011, 08:19 PM -
playing music while program runs
By liluma in forum New To JavaReplies: 2Last Post: 05-04-2011, 05:16 PM -
Music in Java Program
By AWPtic in forum New To JavaReplies: 1Last Post: 04-06-2009, 06:35 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks