Search code examples
javablackberryaudiomp3blackberry-simulator

Playing sound on BlackBerry gives an error


I'm having trouble getting a short MP3 file to play in a very small app I'm writing to learn how to develop for the BlackBerry.

Because I'm a newbie at BlackBerry development, I've uploaded my Eclipse project for the app to http://stroke.sampablokuper.com/stroke.zip because I don't know if the problem's with my Java programming, or the way I've laid out the resources in my project, or something else.

It's a very small project - only one Java file & three media files - so please help me by seeing if you can run it without errors in the Curve 8520 simulator on your computer. (It's designed for the 8520, because that's the phone a friend of mine has; I don't have a BB myself - yet!)

The idea is that when the user presses/scrolls "down" on the trackball/pad, a sound will be played, but currently instead of the sound, I just get an error message: javax.microedition.media.MediaException .

I've tried to debug this, but as I say, I'm a total newbie to BB development, so I don't really know how to make sense of the information I get from the breakpoints I've set.

Please can you tell me where I've gone wrong?

I really want to finish this before Christmas; please help!

Thanks in advance :)

EDIT: here's the relevant portion of the code, stripped down as much as possible:

public boolean navigationMovement(int dx, int dy, int status, int time) {
    if (dx == 0 && dy == 1)// DOWN
    {
        makeNoise("growl");
    }
    return true;
}

private void makeNoise(String action) {
    if (action == "growl") {
        Dialog.alert("GROWL");
        try 
        {
            Player p = javax.microedition.media.Manager.createPlayer("growl.mp3");
            p.realize();
            VolumeControl volume = (VolumeControl)p.getControl("VolumeControl");
            volume.setLevel(30);
            p.prefetch();
            p.start();

        }
        catch(MediaException me)
        {
            Dialog.alert(me.toString());
        }
        catch(IOException ioe)
        {
            Dialog.alert(ioe.toString());
        }
    }
    invalidate();
}

Further edit I've removed the link to download the project, since the problem did indeed appear to be with the code, and is now solved anyway.


Solution

  • if you have mp3 file on SDCard your URI should be file:///SDCard/<file>.mp3 but if you are playing it from application then getResourceAsStream is the answer