Package model

Source Code of model.music

package model;

import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;

import javax.sound.midi.InvalidMidiDataException;
import javax.sound.midi.MidiSystem;
import javax.sound.midi.MidiUnavailableException;
import javax.sound.midi.Sequence;
import javax.sound.midi.Sequencer;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.UnsupportedAudioFileException;

public class music extends Thread
{
  private int type;
  private Clip clip;
 
  public music(int t)
  {
    type=t;
    if(type==2)
    {
      AudioInputStream ais;
      try {
       
        ais = AudioSystem.getAudioInputStream(new File("elevatordoor.wav"));
          clip = AudioSystem.getClip();
            clip.open(ais);
      }
      catch (UnsupportedAudioFileException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
      catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
      catch (LineUnavailableException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }
  }
  public void run()
  {
    if(type==1)//main loop song
    {
      try {
            // From file
            Sequence sequence = MidiSystem.getSequence(new File("onestop.mid"));
        //Sequence sequence = MidiSystem.getSequence(new File("fireflames.mid"));
                 
            // Create a sequencer for the sequence
            Sequencer sequencer = MidiSystem.getSequencer();
            sequencer.open();
            sequencer.setSequence(sequence);
       
            // Start playing
            sequencer.start();
        } catch (MalformedURLException e) {
        } catch (IOException e) {
        } catch (MidiUnavailableException e) {
        } catch (InvalidMidiDataException e) {
        }
    }
    else if(type==2)
    {
      clip.setFramePosition(0);
          clip.start();
    }
   
  }

}
TOP

Related Classes of model.music

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.