java获取midi,Java MidiFileReader.getSequence方法代码示例

import javax.sound.midi.spi.MidiFileReader; //导入方法依赖的package包/类

/**

* Obtains a MIDI sequence from the specified URL. The URL must point to

* valid MIDI file data for a file type recognized by the system.

*

* This operation can only succeed for files of a type which can be parsed

* by an installed file reader. It may fail with an

* {@code InvalidMidiDataException} even for valid files if no compatible

* file reader is installed. It will also fail with an

* {@code InvalidMidiDataException} if a compatible file reader is

* installed, but encounters errors while constructing the {@code Sequence}

* object from the file data.

*

* @param url the URL from which the {@code Sequence} should be constructed

* @return a {@code Sequence} object based on the MIDI file data pointed to

* by the URL

* @throws InvalidMidiDataException if the URL does not point to valid MIDI

* file data recognized by the system

* @throws IOException if an I/O exception occurs while accessing the URL

* @throws NullPointerException if {@code url} is {@code null}

*/

public static Sequence getSequence(final URL url)

throws InvalidMidiDataException, IOException {

Objects.requireNonNull(url);

List providers = getMidiFileReaders();

Sequence sequence = null;

for(int i = 0; i < providers.size(); i++) {

MidiFileReader reader = providers.get(i);

try {

sequence = reader.getSequence( url ); // throws IOException

break;

} catch (InvalidMidiDataException e) {

continue;

}

}

if( sequence==null ) {

throw new InvalidMidiDataException("could not get sequence from URL");

} else {

return sequence;

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值