Go Back   Flash Flash Revolution > General Discussion > Chit Chat
Register FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
Old 05-17-2006, 01:38 PM   #1
esupin
FFR Player
 
esupin's Avatar
 
Join Date: Nov 2003
Location: Alphabet City, Manhattan
Age: 35
Posts: 1,756
Send a message via AIM to esupin
Default Adding music to your java program

It's a simple question, but I can't find how to do it on Google. I'm probably searching for the wrong things, but I'm trying to figure out how to make a program play music from a mpg or wmp file(like the background music, and a fanfare when you beat a level). It should only take a few lines, I'm assuming.

Anyone know how? BTW, no, I don't want to know how to make my own music using swing or whatever.
__________________

http://www.youtube.com/esupin
esupin is offline   Reply With Quote
Old 05-17-2006, 10:02 PM   #2
SqNtz_xoombotvx
FFR Player
 
SqNtz_xoombotvx's Avatar
 
Join Date: Jan 2006
Location: Bozeman, MT
Age: 36
Posts: 220
Send a message via AIM to SqNtz_xoombotvx Send a message via MSN to SqNtz_xoombotvx Send a message via Yahoo to SqNtz_xoombotvx
Default Re: Adding music to your java program

There's a way to do it using the Java Sound API. A much simpler way exists, which Kajakalaka Studios has used in the past and would be happy to share with you. Go to itmorr.com and in the downloads page you'll find a poorly made game named 'Safari Battleship'. That's not the source code, but it is a demo of what the background music is like when it's done.

You have to have a small sound clip. We're not sure if it buffers the sound and the limit is memory or what. Just trim down the sound clip and make it loopable if you can. Here's how to do background music on a Java app.

//import your stuff.
import sun.audio.AudioPlayer;
import sun.audio.AudioStream;

//make a new AudioPlayer.
myBackgroundPlayer = AudioPlayer.player;

//use a try block in case the file doesnt exist.
try {
myBackgroundMusic = new AudioStream(new FileInputStream("safari2.wav"));
myData = myBackgroundMusic.getData();
myLoop = new ContinuousAudioDataStream(myData);
}
catch(IOException error) {}

// play background music.
myBackgroundPlayer.start(myLoop);


if the song doesnt load, try a smaller song file and make sure it's the code's fault and not the song's fault for being too big. the way to do background music listed above is not very up to date and is probably rarely used, but it might be worth a try.

also, make sure everything you just initialized in that code is declared either before being initialized or as an instance variable.

if you want a copy of the source code we used, send an email to kajakalaka.studios@gmail.com.
__________________


Last edited by SqNtz_xoombotvx; 05-17-2006 at 10:04 PM..
SqNtz_xoombotvx is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



All times are GMT -5. The time now is 09:19 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright FlashFlashRevolution