java编程播放midi音乐

2008-02-23 09:28:47来源:互联网 阅读 ()

新老客户大回馈,云服务器低至5折

package test;

import Javax.sound.midi.*;
import javax.sound.sampled.*;
import java.io.*;

/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Company: SinoSoft</p>
* @author pete
* @version 1.0
*/

public class PlayMidi implements Runnable{
File sound;
Sequence seq;
Sequencer midi;
Thread runner;
public PlayMidi(String f){
try {
sound=new File(f);
seq=MidiSystem.getSequence(sound);
midi=MidiSystem.getSequencer();
midi.open();
midi.setSequence(seq);
}
catch (Exception ex) {
}
}

public void run(){
try {
while(true){
if(!midi.isRunning())midi.start();
Thread.sleep(1000);
}
}
catch (Exception ex) {
ex.printStackTrace();
}
}
public void playMidi(){
try
{
//midi.start();
if(runner==null){
runner=new Thread(this);
runner.start();
}
}
catch (Exception ex)
{
}
}
public void stopMidi(){
try
{
runner.stop();
runner=null;
midi.stop();
}
catch (Exception ex)
{
}
}

public static void main(String[] args)
{
PlayMidi playMidi1 = new PlayMidi("mytest.mid");
playMidi1.playMidi();
playMidi1.stopMidi();
}
}

上一篇: 让你找不到问题根源的问题,往往是一个低级的失误造成的!
下一篇: osworkflow 练习 之 beanshell

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:JFCUnit测试GUI的一个实例(配置篇)

下一篇:Spring例子JPetStore分析---------1