java midi 解析_Java MidiFileReader.getMidiFileFormat方法代码示例

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

/**

* Obtains the MIDI file format of the data in 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 determining the file format.

*

* @param url the URL from which file format information should be

* extracted

* @return a {@code MidiFileFormat} object describing the MIDI file format

* @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}

* @see #getMidiFileFormat(InputStream)

* @see #getMidiFileFormat(File)

*/

public static MidiFileFormat getMidiFileFormat(final URL url)

throws InvalidMidiDataException, IOException {

Objects.requireNonNull(url);

List providers = getMidiFileReaders();

MidiFileFormat format = null;

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

MidiFileReader reader = providers.get(i);

try {

format = reader.getMidiFileFormat( url ); // throws IOException

break;

} catch (InvalidMidiDataException e) {

continue;

}

}

if( format==null ) {

throw new InvalidMidiDataException("url is not a supported file type");

} else {

return format;

}

}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值