Java Tutorial – Add music/sound to java program: background music help
This tutorial will show you how to add background music or a sound file to your Java program. The “music” method I made in this program can be used to play any sound file from the system into a Java program.
May 8, 2010 | Filed Under Java Tutorials
Comments
22 Responses to “Java Tutorial – Add music/sound to java program: background music help”
Powered by Yahoo! Answers
awesome!
thanks dude!! =]
I dont know whats going on but i got this warning when i tried compling the code.
Sound.java:32: warning: sun.audio.AudioStream is Sun proprietary API and may be removed in a future release
BMG = new AudioStream(new FileInputStream(“safari2.wav”));
I dont think a warning should matter to weather or not the program will work
Thanks for letting me know, I found the problem. Instead of Data I put date and BGM to BMG..^^’
thanks
Thanks for EXCELENT tutorials.
A quick question(without trying).
If U delete the file(safari2), how come the program still run? Must be a catch error(file not found).
Great tutorial man, any one that uses netbeans?
i put the mp3 file in the same folder as the main file but the mp3 file still cant be found
You can put the full path of the file instead of just putting the file name. That way the program will know exactly where to look. For example you can put “C:/Users/My Documents/Safari2.mp3″ instead of putting the file name
Thanks man, ill try that :)
Very helpful thanks!
Any one that knows how to stop the loop?
i have tried
AudioPlayer.player.stop (continuousaudiostream);
but it wont stop =/
Access restriction: The type AudioData is not accessible due to restriction on required library C:\Program Files\Java\jre6\lib\rt.jar
Why am I getting this error for everything involving AudioPlayer?
In eclipse do this: Window -> Preferences -> Java -> Compiler -> Errors/Warnings -> Deprecated and restricted API -> Forbidden reference (access rules) -> set it to ‘Warnings’
@joint08 You can put it outside the src folder.
Not only will music not play on my first button, but for my second button I get this for the AudioData = MD;
“The local variable MD is never read”
Any help? thanks.
scratch that, now I only have a problem with buttons 4-10 (i made a program with 10 buttons rather than 1)
and I get errors on the button(#).addActionListner (action(#) ());
saying that the action cannot be resolved as a type
any help?
Thank you! This tutorial was very helpful. Except, how do you make it so that it only plays the clip once and not as a loop.
i cannot use this in java 1.6 it says restricted access on audio player stream and data and that it will be removed in a future realease
does java only support wav files?
what’s a good song for a puzzle game i’m making?
Ive been making some awesome music with a program called DubTurbo. It has only just been released but i downloaded there trial. buydubturbo . com Definetly the cheapest music production software you can buy. BuyDubTurbo . com