Results 1 to 6 of 6
  1. #1
    Hees is offline Member
    Join Date
    Jun 2010
    Posts
    3
    Rep Power
    0

    Default Playing mid in java pls help

    Hellou people please i need your help.Im doing tamagotchi and i need music in my program.My problem is:Song dont play good i need to play 1 time no again and again after 4 seconds and mixing to yourself.Please help me? I try everything what i found on net nothing helps.


    try {
    // From file
    Sequence pesnicka = MidiSystem.getSequence(new File("for_elise.mid"));

    // Create a sequencer for the sequence
    Sequencer sequencer = MidiSystem.getSequencer();
    sequencer.open();

    sequencer.setSequence(pesnicka);

    // Start playing
    sequencer.start();

    } catch (MalformedURLException s) {
    } catch (IOException s) {
    } catch (MidiUnavailableException s) {
    } catch (InvalidMidiDataException s) {
    }

  2. #2
    Zack's Avatar
    Zack is offline Senior Member
    Join Date
    Jun 2010
    Location
    Destiny Islands
    Posts
    692
    Rep Power
    5

    Default

    To fix the looping problem (playing again and again), try this:
    Java Code:
    try {
        // From file
        Sequence pesnicka = MidiSystem.getSequence(new File("for_elise.mid"));
    
        // Create a sequencer for the sequence
        Sequencer sequencer = MidiSystem.getSequencer();
        sequencer.open();
    
        sequencer.setSequence(pesnicka);
    
        // Start playing
        sequencer.setLoopCount(0);
        sequencer.start();
    } catch (MalformedURLException s) {
    } catch (IOException s) {
    } catch (MidiUnavailableException s) {
    } catch (InvalidMidiDataException s) {
    }

  3. #3
    Hees is offline Member
    Join Date
    Jun 2010
    Posts
    3
    Rep Power
    0

    Default

    sorry but this no help me...i try but working the same like old one.

  4. #4
    Zack's Avatar
    Zack is offline Senior Member
    Join Date
    Jun 2010
    Location
    Destiny Islands
    Posts
    692
    Rep Power
    5

    Default

    First try running your for_elise.mid in a media player; it may be corrupted (bad MID file) or it may be playing correctly, the song Fur Elise is very repetitive.

    Other than that, the only thing I can suggest is putting sequencer.open(); after sequencer.setSequence(pesnicka);.

    PS: I'm headed home now, I'll test this code out when I get there.

  5. #5
    Hees is offline Member
    Join Date
    Jun 2010
    Posts
    3
    Rep Power
    0

    Default

    I try more than one song...and i use media player .) something must be wrong

  6. #6
    Webuser is offline Senior Member
    Join Date
    Dec 2008
    Posts
    526
    Rep Power
    0

    Default

    Emm...

    Does the class have a method like a
    sequencer.stop();
    ?
    If my answer helped you. Please click my "REP" button and add a comment
    Have a Good Java Coding :)

Similar Threads

  1. Playing an Animated GIF
    By c0m4ndo45 in forum Java 2D
    Replies: 3
    Last Post: 04-24-2009, 11:47 AM
  2. playing audio in J-App??
    By ashton in forum New To Java
    Replies: 3
    Last Post: 01-30-2009, 09:50 AM
  3. Java Error when playing POGO
    By coffeeswirlz in forum Advanced Java
    Replies: 1
    Last Post: 11-25-2008, 03:34 AM
  4. Re-playing sound
    By JSK in forum CLDC and MIDP
    Replies: 0
    Last Post: 02-06-2008, 12:34 PM
  5. Playing sound in applet??????
    By Bagesh in forum Java Applets
    Replies: 2
    Last Post: 07-13-2007, 05:46 PM

Posting Permissions

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