#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    23
    Rep Power
    0

    Playing java songs


    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");
    	}
  2. #2
  3. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,711
    Rep Power
    348
    Add a call to the printStackTrace() method in the catch block so you can see what the problem is.

IMN logo majestic logo threadwatch logo seochat tools logo