本文整理匯總了Java中javax.sound.midi.MidiSystem.getMidiFileFormat方法的典型用法代碼示例。如果您正苦於以下問題:Java MidiSystem.getMidiFileFormat方法的具體用法?Java MidiSystem.getMidiFileFormat怎麽用?Java MidiSystem.getMidiFileFormat使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.sound.midi.MidiSystem
的用法示例。
在下文中一共展示了MidiSystem.getMidiFileFormat方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: JavaSoundAudioClip
import javax.sound.midi.MidiSystem; //導入方法依賴的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");
}
}
示例2: fillMetadata
import javax.sound.midi.MidiSystem; //導入方法依賴的package包/類
@Override
public void fillMetadata(final Content content, final Log logger) throws Exception
{
final URL url = content.getURL(); // Throws NullPointerException if content is null. May throw SecurityException, IllegalArgumentException, MalformedURLException.
try
{
final AudioFileFormat audioFileFormat = AudioSystem.getAudioFileFormat(url); // May throw UnsupportedAudioFileException, IOException.
content.setWidth(0);
content.setHeight(0);
final AudioFormat audioFormat = audioFileFormat.getFormat();
if ((audioFileFormat.getFrameLength() == AudioSystem.NOT_SPECIFIED) || (audioFormat.getSampleRate() == (float) AudioSystem.NOT_SPECIFIED))
{
logger.debug("Unknown audio duration");
}
else
{
content.setDuration((long)(((float) audioFileFormat.getFrameLength() * 1000.0f) / audioFormat.getSampleRate()));
}
return;
}
catch (UnsupportedAudioFileException e)
{
// Try the next format.
logger.debug(e.toString());
}
final MidiFileFormat midiFormat = MidiSystem.getMidiFileFormat(url); // May throw InvalidMidiDataException, IOException.
content.setWidth(0);
content.setHeight(0);
final long duration = midiFormat.getMicrosecondLength();
if (duration == MidiFileFormat.UNKNOWN_LENGTH)
{
logger.debug("Unknown MIDI duration");
}
else
{
content.setDuration((duration + 999L) / 1000L);
}
}
示例3: loadMidi
import javax.sound.midi.MidiSystem; //導入方法依賴的package包/類
/**
* Parses a MIDI file and returns a Pattern. This is an excellent example
* of JFugue's Parser-Renderer architecture:
*
* <pre>
* MidiParser parser = new MidiParser();
* MusicStringRenderer renderer = new MusicStringRenderer();
* parser.addParserListener(renderer);
* parser.parse(sequence);
* </pre>
*
* @param filename The name of the MIDI file
* @return a Pattern containing the MusicString representing the MIDI music
* @throws IOException If there is a problem opening the MIDI file
* @throws InvalidMidiDataException If there is a problem obtaining MIDI resources
*/
public Pattern loadMidi(File file) throws IOException, InvalidMidiDataException
{
MidiFileFormat format = MidiSystem.getMidiFileFormat(file);
this.sequenceTiming = format.getDivisionType();
this.resolution = format.getResolution();
return Pattern.loadMidi(file);
}