Sign in to follow this  
TheTraveller

[java] J2ME Audio

Recommended Posts

TheTraveller    158
Anyone PLEASE HELP!, I tried posting this on the Sprint Developer's site, but no one has responded and/or knows how to solve my problem. I am trying to deploy a game to the Sprint LG phone. I have a VeriSign digital signing certificate, and I went through some other steps to make sure the Sprint phone will download my application. Well, it downloads beautifully and it runs. However, it gives me a "nullPointerException," when trying to "play" the mp3 files. Ironically, it doesn't give me an error when loading them. It runs in my emulator fine, and I verified that the sound files are in the JAR file. I'm completely baffled as to why the phone doesn't see the sound file. Here are my JAD permissions: javax.microedition.media.control.RecordControl javax.microedition.media.Manager Here is the code I use to load the audio file, where "effect" is a Player object:
private void initializeMedia()
{
.
.
.
  try {
    InputStream is2 = getClass().getResourceAsStream(effectsFile);
    effect = Manager.createPlayer(is2, "audio/mp3");
  } catch (Exception e) {
    this.midlet.errorMsg("Problem opening effects...\n" + e);
  }
.
.
.
}

protected void playEffects()
{
  if(isMusicOn)
  {
    try {
       effect.start();
    } catch (Exception e ) {
       this.midlet.errorMsg("Problem playing effect...\n" + e);
    }
  }
}

Also note that the effect variable is "static," since the Manager.createPlayer method is static. I tried making the variable not static, and that didn't help either. Why would it not give me an error when loading the said mp3 file, but then give me the nullPointerException error when trying to play it?? Any feedback would be GREATLY appreciated.

Share this post


Link to post
Share on other sites
Son of Cain    480
The only thing I can think of now is, maybe you have a classpath configuration properly setup on your production environment (emulator), but not the same on the phone environment.

This is a shot in the dark.. I only say so because this is quite common when loading resources for Java SE apps; people can see the results on their IDEs, but when running the app by itself, they run into errors because of bad classpaths.

If that is not the case... only the related documentation might help you out, or the people on the forum you mentioned =/

Share this post


Link to post
Share on other sites
shmoove    821
Quote:
Original post by TheTraveller
Why would it not give me an error when loading the said mp3 file, but then give me the nullPointerException error when trying to play it??

Are you sure there is no error when loading the file? Does this.midlet.errorMsg() show the error someplace you can check on the device (does it give you any on-screen output, or write something into a file you can check later)?

Because from what I can see, if you're missing an Exception thrown in initializeMedia() then you will get a NullPointerException in playEffects() when trying to use the "effects" variable which might be uninitialized.

shmoove

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this