本文整理汇总了Java中javax.sound.midi.MidiFileFormat类的典型用法代码示例。如果您正苦于以下问题:Java MidiFileFormat类的具体用法?Java MidiFileFormat怎么用?Java MidiFileFormat使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MidiFileFormat类属于javax.sound.midi包,在下文中一共展示了MidiFileFormat类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getMidiFileFormat
import javax.sound.midi.MidiFileFormat; //导入依赖的package包/类
public MidiFileFormat getMidiFileFormat(File file) throws InvalidMidiDataException, IOException {
FileInputStream fis = new FileInputStream(file); // throws IOException
BufferedInputStream bis = new BufferedInputStream(fis, bisBufferSize);
// $$fb 2002-04-17: part of fix for 4635286: MidiSystem.getMidiFileFormat() returns format having invalid length
long length = file.length();
if (length > Integer.MAX_VALUE) {
length = MidiFileFormat.UNKNOWN_LENGTH;
}
MidiFileFormat fileFormat = null;
try {
fileFormat = getMidiFileFormatFromStream(bis, (int) length, null);
} finally {
bis.close();
}
return fileFormat;
}
示例2: getSequence
import javax.sound.midi.MidiFileFormat; //导入依赖的package包/类
public Sequence getSequence(InputStream stream) throws InvalidMidiDataException, IOException {
SMFParser smfParser = new SMFParser();
MidiFileFormat format = getMidiFileFormatFromStream(stream,
MidiFileFormat.UNKNOWN_LENGTH,
smfParser);
// must be MIDI Type 0 or Type 1
if ((format.getType() != 0) && (format.getType() != 1)) {
throw new InvalidMidiDataException("Invalid or unsupported file type: " + format.getType());
}
// construct the sequence object
Sequence sequence = new Sequence(format.getDivisionType(), format.getResolution());
// for each track, go to the beginning and read the track events
for (int i = 0; i < smfParser.tracks; i++) {
if (smfParser.nextTrack()) {
smfParser.readTrack(sequence.createTrack());
} else {
break;
}
}
return sequence;
}
示例3: getMidiFileFormat
import javax.sound.midi.MidiFileFormat; //导入依赖的package包/类
@Override
public MidiFileFormat getMidiFileFormat(File file) throws InvalidMidiDataException, IOException {
FileInputStream fis = new FileInputStream(file); // throws IOException
BufferedInputStream bis = new BufferedInputStream(fis, bisBufferSize);
// $$fb 2002-04-17: part of fix for 4635286: MidiSystem.getMidiFileFormat() returns format having invalid length
long length = file.length();
if (length > Integer.MAX_VALUE) {
length = MidiFileFormat.UNKNOWN_LENGTH;
}
MidiFileFormat fileFormat = null;
try {
fileFormat = getMidiFileFormatFromStream(bis, (int) length, null);
} finally {
bis.close();
}
return fileFormat;
}
示例4: getSequence
import javax.sound.midi.MidiFileFormat; //导入依赖的package包/类
@Override
public Sequence getSequence(InputStream stream) throws InvalidMidiDataException, IOException {
SMFParser smfParser = new SMFParser();
MidiFileFormat format = getMidiFileFormatFromStream(stream,
MidiFileFormat.UNKNOWN_LENGTH,
smfParser);
// must be MIDI Type 0 or Type 1
if ((format.getType() != 0) && (format.getType() != 1)) {
throw new InvalidMidiDataException("Invalid or unsupported file type: " + format.getType());
}
// construct the sequence object
Sequence sequence = new Sequence(format.getDivisionType(), format.getResolution());
// for each track, go to the beginning and read the track events
for (int i = 0; i < smfParser.tracks; i++) {
if (smfParser.nextTrack()) {
smfParser.readTrack(sequence.createTrack());
} else {
break;
}
}
return sequence;
}
示例5: JavaSoundAudioClip
import javax.sound.midi.MidiFileFormat; //导入依赖的package包/类
public JavaSoundAudioClip(InputStream in) throws IOException {
if (DEBUG || Printer.debug)Printer.debug("JavaSoundAudioClip.<init>");
BufferedInputStream bis = new BufferedInputStream(in, STREAM_BUFFER_SIZE);
bis.mark(STREAM_BUFFER_SIZE);
boolean success = false;
try {
AudioInputStream as = AudioSystem.getAudioInputStream(bis);
// load the stream data into memory
success = loadAudioData(as);
if (success) {
success = false;
if (loadedAudioByteLength < CLIP_THRESHOLD) {
success = createClip();
}
if (!success) {
success = createSourceDataLine();
}
}
} catch (UnsupportedAudioFileException e) {
// not an audio file
try {
MidiFileFormat mff = MidiSystem.getMidiFileFormat(bis);
success = createSequencer(bis);
} catch (InvalidMidiDataException e1) {
success = false;
}
}
if (!success) {
throw new IOException("Unable to create AudioClip from input stream");
}
}
示例6: getMidiFileFormat
import javax.sound.midi.MidiFileFormat; //导入依赖的package包/类
public MidiFileFormat getMidiFileFormat(URL url)
throws InvalidMidiDataException, IOException
{
InputStream is = url.openStream();
try
{
return getMidiFileFormat(is);
}
finally
{
is.close();
}
}