Thread: [PI] Simple Midi Player

Results 1 to 6 of 6
  1. #1 [PI] Simple Midi Player 
    Registered Member
    Join Date
    Nov 2014
    Posts
    6
    Thanks given
    0
    Thanks received
    0
    Rep Power
    0
    Hello rune-server this is my first post.
    this is a simple midi player that plays midi files from the cache and goes right into SignLink.java in your server works for most pi servers but might need some modifications. you need a couple of sound imports which i forgot.
    start out by importing these two
    Code:
    import javax.sound.sampled.*;
    import javax.sound.midi.*;
    now somewhere add this method
    Code:
    	public static void playMidi(String location) {
    		music = null;
    		synthesizer = null;
    		sequence = null;
    		File midiFile = new File(findcachedir() + "/Music/" + location + ".mid");
    		try {
    			sequence = MidiSystem.getSequence(midiFile);
    			music = MidiSystem.getSequencer();
    			music.open();
    			music.setSequence(sequence);
    		} catch (Exception e) {
    			System.err.println("Problem loading MIDI file.");
    			e.printStackTrace();
    			return;
    		}
    		if (music instanceof Synthesizer) {
    			synthesizer = (Synthesizer) music;
    		} else {
    			try {
    				synthesizer = MidiSystem.getSynthesizer();
    				synthesizer.open();
    				if (synthesizer.getDefaultSoundbank() == null) {
    					music.getTransmitter().setReceiver(MidiSystem.getReceiver());
    				} else {
    					music.getTransmitter().setReceiver(synthesizer.getReceiver());
    				}
    			} catch (Exception e) {
    				e.printStackTrace();
    				return;
    			}
    		}
    		music.setLoopCount(Sequencer.LOOP_CONTINUOUSLY);
    		music.start();
    	}
    this plays midi files with SignLink.playMidi(filename); the it automatically adds the .mid extension. plays from cachedir/Music/ and plays filename.mid inside of that folder.
    this can be added to startup method in client.java after the client downloads the cache to play the login music. thats all good and everything but what happens when you want to stop it at login. add this to signlink.java as well
    Code:
    	public static void stopMidi() {
    		try {
    			if ((music == null) || (!music.isRunning())) return;
    			music.stop();
    			music.close();
    		}
    		catch (Exception e) {
    	     	System.err.println("MidiPlayer: " + e);
    		}
    		music = null;
    	}
    this stops the song with SignLink.stopMidi();
    so at login you stop the current song and then play the next song you want to play.

    this is just a simple tutorial. i got this far but idk how to make it play diffrent songs from the songs tab. you can make client sided commands to change the song but thats all i know.
    if anyone has a tutorial out there on how to make server packets change the song please tell me. i dont know if this requires any constants but just use eclispe or and ide and it should tell you want you're missing

    *edit*
    you need to add
    Code:
    public static Sequencer music = null;
    public static Sequence sequence = null;
    public static Synthesizer synthesizer = null;
    somewhere in there
    Last edited by NoelX; 11-23-2014 at 09:01 PM. Reason: forgot
    Reply With Quote  
     

  2. #2  
    Registered Member Emre's Avatar
    Join Date
    Jan 2014
    Posts
    596
    Thanks given
    91
    Thanks received
    61
    Rep Power
    7
    You know you can just use MediaPlayer right?
    Reply With Quote  
     

  3. #3  
    Registered Member
    Join Date
    May 2012
    Posts
    445
    Thanks given
    31
    Thanks received
    19
    Rep Power
    48
    Quote Originally Posted by Emre View Post
    You know you can just use MediaPlayer right?
    You know he ripped it from a server? Called Biohazard.
    Reply With Quote  
     

  4. #4  
    Registered Member
    Join Date
    Nov 2014
    Posts
    6
    Thanks given
    0
    Thanks received
    0
    Rep Power
    0
    Quote Originally Posted by No1killme View Post
    You know he ripped it from a server? Called Biohazard.
    i didnt rip this from any server. i got this from the java website. and what the hell is biohazard.
    Reply With Quote  
     

  5. #5  
    🍕

    Linus's Avatar
    Join Date
    Dec 2008
    Age
    31
    Posts
    2,779
    Thanks given
    974
    Thanks received
    411
    Rep Power
    0
    SignLink.java in your server works for most pi servers but might need some modifications
    Cringe

    ╠╬╣
    ╦╦
    ╠╬╬╬╣
    ╠╬╬╬╬╬╬╣
    ╠╬╬╬╬╬╬╣
    ╚╩╩╩╩╩╩╝

    ╠╬╬╬╣



    Reply With Quote  
     

  6. #6  
    Banned [PI] Simple Midi Player Market Banned


    Join Date
    Jan 2011
    Age
    26
    Posts
    3,112
    Thanks given
    1,198
    Thanks received
    1,479
    Rep Power
    0
    needs fading or idc
    Reply With Quote  
     


Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. [PI] simple "player rank: ____" in quest tab
    By 24jared24 in forum Tutorials
    Replies: 16
    Last Post: 03-13-2014, 07:00 PM
  2. [PI]Simple players online to image
    By wuperr in forum Snippets
    Replies: 33
    Last Post: 09-21-2011, 07:59 PM
  3. [PI] Re-enabling player clipping
    By Throat in forum Help
    Replies: 1
    Last Post: 07-26-2010, 12:46 PM
  4. [PI] Simple Question!
    By dixienormus1 in forum Help
    Replies: 1
    Last Post: 07-05-2010, 06:05 PM
  5. Simple error, players online.
    By infallible in forum Help
    Replies: 4
    Last Post: 03-01-2010, 01:17 AM
Tags for this Thread

View Tag Cloud

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