Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - metapod

Pages: [1]
1
Other Support / SoundSystem playbackgroundmusic null pointer
« on: January 31, 2014, 11:05:13 AM »
I'm having a hard time getting started with soundsystem playing an ogg background music file...

Any idea why calling playBGM gives me a null pointer? The file DOES exist. Thanks!

Code: [Select]
public class SoundPlayer {
 
  private SoundSystem soundSystem;
  public static final String BGM = "BGM";
 
  public SoundPlayer() {
    try {
      SoundSystemConfig.addLibrary(LibraryJavaSound.class);
      SoundSystemConfig.setCodec("ogg", CodecJOrbis.class);
      SoundSystemConfig.setCodec("wav", CodecWav.class);
    }
    catch(SoundSystemException e)
    {
      System.err.println("error linking with the plug-ins" );
    }
   
    SoundSystem soundSystem = new SoundSystem();
   
    soundSystem.setMasterVolume(1.0f);
    soundSystem.setVolume(BGM, 1.0f);
  }
 
  public void playBGM(String name) {
    File f = new File("res/music/" + name);
    if (!f.exists()) return;

    try {
      URL path = f.toURI().toURL();
      System.out.println(path);
     
      soundSystem.backgroundMusic(BGM, path, name, true);
      soundSystem.setVolume(BGM, 1.0f);
    } catch (MalformedURLException e) {

      e.printStackTrace();
    }
  }
}

Pages: [1]