0

My logic for run background music when click button.

        b.addActionListener(new ActionListener(){

            public void actionPerformed(ActionEvent e)
            {
                ContinuousAudioDataStream loop=null;

                AudioPlayer mgp=AudioPlayer.player;
                try{
                AudioStream bgm=new AudioStream(new FileInputStream("C:/Users/Public/Music/Sample Music/Sleep Away.mp3"));
                AudioData md=bgm.getData();
                loop=new ContinuousAudioDataStream(md);

                }
                catch(IOException ex){

                }
                mgp.start(loop);
                loop=null;
            }
        });

Hello EveryOne,

I am new to Java and creating a small program to add background music but its not working.
I have one qury do I need to add any .jar file in my lib folder for sound?

Thanks

2
Contributors
1
Reply
3
Views
4 Years
Discussion Span
Last Post by harinath_2007
1

Dont leave the catch block empty. Add ex.printStackTrace() in the catch block. So that you will know the errors if any. (Remember : Never ever leave the catch block empty in you whole programming life because that will make your life worse:) )

And you do not need to add any jar file unless you use third-party libraries.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.