Results 1 to 2 of 2
  1. #1
    jumpman8947 is offline Member
    Join Date
    Feb 2013
    Rep Power

    Default 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 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)
    	public static void music()
    		AudioPlayer MGP = AudioPlayer.player;
    		AudioStream	BGM;
    		AudioData MD;
    		ContinuousAudioDataStream loop = null;
    		BGM = new AudioStream(new FileInputStream("bear.wav"));
    		MD = BGM.getData();
    		loop = new ContinuousAudioDataStream(MD);
    	}catch(IOException error){JOptionPane.showMessageDialog(null, "file not found");}
    	JOptionPane.showMessageDialog(null, "music should be playing");

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Rep Power

    Default Re: playing music in java

    You should be using javax.sound, not the internal 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.

    ** This space for rent **

Similar Threads

  1. How to Put Music Into Java?
    By DRLC in forum New To Java
    Replies: 1
    Last Post: 09-07-2012, 01:10 AM
  2. playing music
    By snowhite in forum Java Servlet
    Replies: 5
    Last Post: 05-06-2012, 01:41 PM
  3. Java, Playing Music?
    By Alerhau in forum New To Java
    Replies: 3
    Last Post: 08-18-2011, 08:19 PM
  4. playing music while program runs
    By liluma in forum New To Java
    Replies: 2
    Last Post: 05-04-2011, 05:16 PM
  5. Music in Java Program
    By AWPtic in forum New To Java
    Replies: 1
    Last Post: 04-06-2009, 06:35 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts