Getting wma files to play?

Hi there,

Am trying to get some background music for my app, am looking at using a ".wma" track.  Is this possible with jMonkey? Is there some sort of conversion that needs to be done first, as with models?



Thanks :slight_smile:

Sure, if you want to convert, you can re-encode your wma as ogg. That would be a good steps towards freeing yourself from the shackles of proprietary formats… might as well install Linux while you are at it (just kidding about the Linux part, but it's always worth a try :D).



Once you have converted you sound file into ogg, it's very easy to play in jme. Here is an example:



import com.jmex.audio.AudioSystem;
import com.jmex.audio.AudioTrack;
import com.jmex.audio.AudioTrack.TrackType;
import com.jmex.audio.MusicTrackQueue.RepeatType;

public class TestAudioSystem {

   public static void main(String[] args) throws Exception {
      AudioSystem audio = AudioSystem.getSystem();
      
        AudioTrack track = audio.createAudioTrack(
              TestAudioSystem.class.getClassLoader().getResource(
                    "mypackage/myogg.ogg"),
              false);//new File("mydir/myogg.ogg").toURI().toURL();
        track.setType(TrackType.MUSIC);
        track.setRelative(true);
        track.setTargetVolume(0.7f);
        track.setLooping(false);
        audio.getMusicQueue().addTrack(track);
       
        audio.getMusicQueue().setRepeatType(RepeatType.ALL);
        audio.getMusicQueue().setCrossfadeinTime(2.5f);
        audio.getMusicQueue().setCrossfadeoutTime(2.5f);
        audio.getMusicQueue().play();
       
          AudioSystem.getSystem().update();
          
          // sleep for a bit so that the program doesn't exit, otherwise the music
          // will stop playing.
          Thread.sleep(10000);
   }
}

Depending on the file if it's using encoding you can do a little hack to get DRM removal by using Windows Media Player to burn to a CD and then use Windows Media Player to rip it as MP3s (you have to specify this in the options) and there you have an MP3 without DRM…not that I've ever done this before. :-p

There is a good chance the media player is inserting some garbage (digital fingerprint data) when burning to a cd…

Ah ok - found some nice conversion software on internet, so now have my file as a ".ogg". :slight_smile: I tried the test code, however, I get this error:



22-Dec-2007 17:00:23 com.jmex.audio.openal.OpenALSystem setupSourcePool
INFO: max source channels: 23
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
   at java.util.Arrays.copyOf(Arrays.java:2786)
   at java.io.ByteArrayOutputStream.write(ByteArrayOutputStream.java:94)
   at com.jmex.audio.util.AudioLoader.read(AudioLoader.java:124)
   at com.jmex.audio.util.AudioLoader.loadOGG(AudioLoader.java:73)
   at com.jmex.audio.util.AudioLoader.fillBuffer(AudioLoader.java:65)
   at com.jmex.audio.openal.OpenALSystem.createAudioTrack(OpenALSystem.java:180)
   at com.jmex.audio.openal.OpenALSystem.createAudioTrack(OpenALSystem.java:1)
   at assignment.TestAudioSystem.main(TestAudioSystem.java:13)



Do you think this is because I don't have a very good sound card? :) (in fact i don't have one at all.. :S)
Thanks :D

hey! right have been playing around, and changed the stream boolean to "true" so now it plays the first couple of seconds of the track and then stops, so i dont think it is the sound card, am thinking its something to do with the Thread being sleepy, will explore further, in the mean time if anyone has any ideas they would be much appreciated :slight_smile:

Thanks guys :slight_smile:

Im sure you will figure it out. }:-@

The file must be quite large… streaming it will help, yes. Not sure about why it stops playing though, try a forum search maybe?

Hmmm, it seems when I change the bit of code:



Thread.sleep(10000);



to have a couple more zeroes,  it plays more of the track - which confuses me, but if its working then am not fussy :) although am *slightly* concerned that my users won't finish the game before they run out of music....oh well - they'll live :D

a more correct way would be to kick off a secondary thread that loops until your game is exited… in the loop it would sleep for a short time (1000 ms or less probably) and then update the AudioSystem.

Aha! Right - was being a bit daft: when in the main game loop you don't need the Thread bit at all.



Thanks for all your help guys :slight_smile: