×

Discussion Board

Results 1 to 2 of 2
  1. #1
    Registered User
    Join Date
    Nov 2004
    Posts
    9

    Play MIDI in Nokia 5140

    Hi. I'm new in developing J2ME games and now I'm programming a game which has to play several MIDI sounds in Nokia 5140.
    This is my code:

    - I create the player in the constructor of a class named SoundManager (it also implements PlayerListener):

    InputStream is = getClass().getResourceAsStream("/audio/disparar.mid");
    firePlayer = Manager.createPlayer(is, "audio/midi");
    firePlayer.addPlayerListener(this);

    - And the code to play the sound is this:

    if (currentPlayer != null) {
    currentPlayer.stop();
    currentPlayer.deallocate();
    while (playing) {}
    }
    currentPlayer = firePlayer;
    firePlayer.realize();
    firePlayer.prefetch();
    firePlayer.start();
    playing = true;


    public void playerUpdate(Player player, String str, Object obj) {
    if (str == PlayerListener.END_OF_MEDIA) {
    playing = false;
    } else if (str == PlayerListener.STOPPED) {
    playing = false;
    }
    }


    It works for Nokia 6230 emulator, but when I take it to the Nokia 5140 it crashes and shows a java.lang.NullPointerException.

    Does anyone knows what is wrong in my code?
    or
    Could anyone tell me how to do this?

    Can Nokia 5140 play MIDI sounds or only wav ones?

  2. #2
    Super Contributor
    Join Date
    Mar 2005
    Location
    Paris
    Posts
    814
    to know what are the supported media types, use the method getSupportedContentTypes(the protocol you are using (probably resource));
    it will give you the types you can play with your phone

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×