×

Discussion Board

Results 1 to 4 of 4
  1. #1
    Regular Contributor
    Join Date
    Mar 2003
    Location
    Merseyside
    Posts
    61

    Playing a MIDI file(well, trying to)

    Ok, using the new 0.2 series60 emulator i have been testing some of the examples from the mmapi docs, the single tone and Tone Sequence Generation worked fine on the emulator but i can't get it to play a midi file using the MIDI Playback with Some Fine-Grained Control example. here's the example and my code:

    EXAMPLE

    Scenario 4: MIDI Playback with Some Fine-Grained Control
    Player p;
    TempoControl tc;

    try {
    p = Manager.createPlayer("http://webserver/tune.mid"
    p.realize();

    // Grab the tempo control.
    tc = (TempoControl)p.getControl("TempoControl"
    tc.setTempo(120000); // 120 beats/min
    p.start();

    } catch (IOException ioe) {
    } catch (MediaException me) { }


    MY CODE

    private void playMIDISound() throws MediaException, IOException{

    Player p;
    TempoControl tc;

    p = Manager.createPlayer("/tune.mid"
    p.realize();

    // Grab the tempo control.
    tc = (TempoControl)p.getControl("TempoControl"
    tc.setTempo(120000); // 120 beats/min
    p.start();

    }

    As you can see i've not changed it much, but when i try to run it i get a MediaException, as though it doesn't like the midi file or cannot load the midi file. The midi file i am using is the midi_song_example.mid
    (Nokia\Tools\Nokia_Developers_Suite_for_J2ME\midi_examples) from the developer suite.

    Does the midi file have to be made in any particular way or does anyone know if i have to initialise anything else or missed anything.


    Cheers
    eC

  2. #2
    Registered User
    Join Date
    Sep 2003
    Posts
    17
    I guess something wrong when you create player. try this:

    Player p;
    TempoControl tc;
    InputStream is = getClass().getResourceAsStream("/filename");
    String ctype="audio/midi";
    try {
    p = Manager.createPlayer(is, ctype);
    p.realize();

    // Grab the tempo control.
    tc = (TempoControl)p.getControl("TempoControl");
    tc.setTempo(120000); // 120 beats/min
    p.start();
    } catch (IOException ioe) {
    } catch (MediaException me) { }

  3. #3
    Registered User
    Join Date
    Sep 2003
    Posts
    17
    one more thing, you should put the midi file in /res subdir.

  4. #4
    Registered User
    Join Date
    Nov 2003
    Posts
    18
    did you get that finally to work?
    i have tried the same code... and "tc" is always null,... maybe thats why the Exception is thrown...?

    anyway:
    i tried this sample code without "TempoControl" and it worked sometimes on the emulator and sometimes not. maybe a bug? because on a 3650 the midi plays well ---

Posting Permissions

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