Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (494)
Games in Android Showcase (114)
games submitted by our members
Games in WIP (563)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Playing audio in game background  (Read 409 times)
0 Members and 1 Guest are viewing this topic.
Offline Doubstract
« Posted 2014-04-22 20:46:45 »

Hello everyone. I have small problem, i need to play audio in my game background while playing game and i cant do that. I used Google, but i cant find anything useful. I don't care about audio format. Please help me.
Offline SauronWatchesYou
« Reply #1 - Posted 2014-04-22 20:49:01 »

Are you using Slick2D to build your game? Also, what sort of music are you looking for?
Offline Doubstract
« Reply #2 - Posted 2014-04-22 21:33:41 »

I am using LWJGL. I have music in wav, mp3, ogg... I don't really care about format.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline BurntPizza
« Reply #3 - Posted 2014-04-22 21:52:52 »

I don't deem myself qualified for LWJGL specific advice, but I will say that .wav's are to be avoided, used a compressed data format, preferably a non-patent encumbered one. (.ogg's are good)

A standard CD-quality wav file takes up over a megabyte for every 6 seconds of audio, massively bloating the game download. A decent quality (160kbps, most won't know the difference) ogg on the other hand is almost 9 times smaller for a given length audio track.

Also, since the audio has to be uncompressed anyway when played (meaning it takes up the full Mb per 6 seconds), for long tracks (background music) you should look into streaming the data from the disk, so that only a small portion is in RAM at any given time.
Offline Spacebeans
« Reply #4 - Posted 2014-04-22 21:55:53 »

I think Slick2D comes with a OGG decoder, but LWJGL is (generally) just for the graphics.

So what you would use is a OGG decoder like JOrbis: http://www.jcraft.com/jorbis/
A really good, in depth tutorial for beginners: http://www.jcraft.com/jorbis/tutorial/Tutorial.html
Offline SauronWatchesYou
« Reply #5 - Posted 2014-04-22 22:07:06 »

Slick2D music is extremely easy to setup but I think it only does support ogg, at least from what I have seen. Sorry I can't help you OP Sad
Offline Spacebeans
« Reply #6 - Posted 2014-04-22 22:10:03 »

If you are using any other format other than ogg, use a converter. I think ogg is one of the best for games, especially because there is no other decoder for Java Pointing.
Offline BurntPizza
« Reply #7 - Posted 2014-04-23 02:29:33 »

If you are using any other format other than ogg, use a converter. I think ogg is one of the best for games, especially because there is no other decoder for Java Pointing.

Ogg is great for many reasons, but it being the only thing available isn't one of them. Try a quick google around.


Speaking of Google: this should get you well on your way, OP
Offline Rayvolution

JGO Kernel


Medals: 197
Projects: 2
Exp: 1 year


Resident Crazyman


« Reply #8 - Posted 2014-04-23 02:43:50 »

I think Slick2D comes with a OGG decoder, but LWJGL is (generally) just for the graphics.

So what you would use is a OGG decoder like JOrbis: http://www.jcraft.com/jorbis/
A really good, in depth tutorial for beginners: http://www.jcraft.com/jorbis/tutorial/Tutorial.html

Yup. OGG is ultra-easy in slick2d. It even keeps the music playing through different game states and everything.

Simply:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
public class YourState extends BasicGameState{
   private Music music;
   
   YourState(int state){
   }
   
   public void init(GameContainer gc, StateBasedGame sbg) throws SlickException{
      //Load up the track you want to play.
     music = new Music("res/yourSong.ogg");
   }
   
   public void enter(GameContainer container, StateBasedGame sbg) throws SlickException{
      //Start the music loop when you first enter the state, will not end until you use music.stop() or .pause() somewhere, even if you change states.
     music.loop();
   }  

- Raymond "Rayvolution" Doerr.
Retro-Pixel Castles - Survival Sim/Builder/Roguelike!
LIVE-STREAMING DEVELOPMENT: http://www.twitch.tv/SG_Rayvolution
Offline Longarmx
« Reply #9 - Posted 2014-04-23 04:11:12 »

LWJGL comes with OpenAL. You can look on the wiki under the OpenAL section for some tutorials to get you started. From the tutorial:
1  
AL10.alSourcePlay(source);
This is all you would need to play the sound (after loading and buffering of course). You can stop or pause it at any time.

You can also use paulscode 3D sound system to easily play sounds in 3D space (though it can also be used for 2D games too!) As noted by the previous posters, .wav is an uncompressed, lossless format and as a result is very large. .ogg would be a better option.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Doubstract
« Reply #10 - Posted 2014-04-23 04:48:07 »

Thanks for help! I will try everything soon.
Offline Doubstract
« Reply #11 - Posted 2014-04-23 11:54:55 »

Everything worked! I used slick2d. Thanks again!
Pages: [1]
  ignore  |  Print  
 
 

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Dwinin (21 views)
2014-09-12 09:08:26

Norakomi (55 views)
2014-09-10 13:57:51

TehJavaDev (66 views)
2014-09-10 06:39:09

Tekkerue (33 views)
2014-09-09 02:24:56

mitcheeb (54 views)
2014-09-08 06:06:29

BurntPizza (38 views)
2014-09-07 01:13:42

Longarmx (24 views)
2014-09-07 01:12:14

Longarmx (30 views)
2014-09-07 01:11:22

Longarmx (28 views)
2014-09-07 01:10:19

mitcheeb (37 views)
2014-09-04 23:08:59
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!