本文整理汇总了Java中javax.sound.midi.MidiFileFormat.UNKNOWN_LENGTH属性的典型用法代码示例。如果您正苦于以下问题:Java MidiFileFormat.UNKNOWN_LENGTH属性的具体用法?Java MidiFileFormat.UNKNOWN_LENGTH怎么用?Java MidiFileFormat.UNKNOWN_LENGTH使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类javax.sound.midi.MidiFileFormat
的用法示例。
在下文中一共展示了MidiFileFormat.UNKNOWN_LENGTH属性的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getMidiFileFormat
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: getMidiFileFormat
@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;
}
示例3: getMidiFileFormatFromStream
private MidiFileFormat getMidiFileFormatFromStream(InputStream stream,
int fileLength,
SMFParser smfParser)
throws InvalidMidiDataException, IOException{
int maxReadLength = 16;
int duration = MidiFileFormat.UNKNOWN_LENGTH;
DataInputStream dis;
if (stream instanceof DataInputStream) {
dis = (DataInputStream) stream;
} else {
dis = new DataInputStream(stream);
}
if (smfParser == null) {
dis.mark(maxReadLength);
} else {
smfParser.stream = dis;
}
int type;
int numtracks;
float divisionType;
int resolution;
try {
int magic = dis.readInt();
if( !(magic == MThd_MAGIC) ) {
// not MIDI
throw new InvalidMidiDataException("not a valid MIDI file");
}
// read header length
int bytesRemaining = dis.readInt() - 6;
type = dis.readShort();
numtracks = dis.readShort();
int timing = dis.readShort();
// decipher the timing code
if (timing > 0) {
// tempo based timing. value is ticks per beat.
divisionType = Sequence.PPQ;
resolution = timing;
} else {
// SMPTE based timing. first decipher the frame code.
int frameCode = -1 * (timing >> 8);
switch(frameCode) {
case 24:
divisionType = Sequence.SMPTE_24;
break;
case 25:
divisionType = Sequence.SMPTE_25;
break;
case 29:
divisionType = Sequence.SMPTE_30DROP;
break;
case 30:
divisionType = Sequence.SMPTE_30;
break;
default:
throw new InvalidMidiDataException("Unknown frame code: " + frameCode);
}
// now determine the timing resolution in ticks per frame.
resolution = timing & 0xFF;
}
if (smfParser != null) {
// remainder of this chunk
dis.skip(bytesRemaining);
smfParser.tracks = numtracks;
}
} finally {
// if only reading the file format, reset the stream
if (smfParser == null) {
dis.reset();
}
}
MidiFileFormat format = new MidiFileFormat(type, divisionType, resolution, fileLength, duration);
return format;
}
示例4: getMidiFileFormat
public MidiFileFormat getMidiFileFormat(InputStream in)
throws InvalidMidiDataException, IOException
{
DataInputStream din;
if (in instanceof DataInputStream)
din = (DataInputStream) in;
else
din = new DataInputStream(in);
int type, ntracks, division, resolution, bytes;
float divisionType;
if (din.readInt() != 0x4d546864) // "MThd"
throw new InvalidMidiDataException("Invalid MIDI chunk header.");
bytes = din.readInt();
if (bytes < 6)
throw new
InvalidMidiDataException("Invalid MIDI chunk header length: " + bytes);
type = din.readShort();
if (type < 0 || type > 2)
throw new
InvalidMidiDataException("Invalid MIDI file type value: " + type);
ntracks = din.readShort();
if (ntracks <= 0)
throw new
InvalidMidiDataException("Invalid number of MIDI tracks: " + ntracks);
division = din.readShort();
if ((division & 0x8000) != 0)
{
division = -((division >>> 8) & 0xFF);
switch (division)
{
case 24:
divisionType = Sequence.SMPTE_24;
break;
case 25:
divisionType = Sequence.SMPTE_25;
break;
case 29:
divisionType = Sequence.SMPTE_30DROP;
break;
case 30:
divisionType = Sequence.SMPTE_30;
break;
default:
throw new
InvalidMidiDataException("Invalid MIDI frame division type: "
+ division);
}
resolution = division & 0xff;
}
else
{
divisionType = Sequence.PPQ;
resolution = division & 0x7fff;
}
// If we haven't read every byte in the header now, just skip the rest.
din.skip(bytes - 6);
return new ExtendedMidiFileFormat(type, divisionType, resolution,
MidiFileFormat.UNKNOWN_LENGTH,
MidiFileFormat.UNKNOWN_LENGTH, ntracks);
}
示例5: getMidiFileFormat
public MidiFileFormat getMidiFileFormat(InputStream in)
throws InvalidMidiDataException, IOException
{
DataInputStream din;
if (in instanceof DataInputStream)
din = (DataInputStream) in;
else
din = new DataInputStream(in);
int type, ntracks, division, resolution, bytes;
float divisionType;
if (din.readInt() != 0x4d546864) // "MThd"
throw new InvalidMidiDataException("Invalid MIDI chunk header.");
bytes = din.readInt();
if (bytes < 6)
throw new
InvalidMidiDataException("Invalid MIDI chunk header length: " + bytes);
type = din.readShort();
if (type < 0 || type > 2)
throw new
InvalidMidiDataException("Invalid MIDI file type value: " + type);
ntracks = din.readShort();
if (ntracks <= 0)
throw new
InvalidMidiDataException("Invalid number of MIDI tracks: " + ntracks);
division = din.readShort();
if ((division & 0x8000) != 0)
{
division = -((division >>> 8) & 0xFF);
switch (division)
{
case 24:
divisionType = Sequence.SMPTE_24;
break;
case 25:
divisionType = Sequence.SMPTE_25;
break;
case 29:
divisionType = Sequence.SMPTE_30DROP;
break;
case 30:
divisionType = Sequence.SMPTE_30;
break;
default:
throw new
InvalidMidiDataException("Invalid MIDI frame division type: "
+ division);
}
resolution = division & 0xff;
}
else
{
divisionType = Sequence.PPQ;
resolution = division & 0x7fff;
}
// If we haven't read every byte in the header now, just skip the rest.
din.skip(bytes - 6);
return new ExtendedMidiFileFormat(type, divisionType, resolution,
MidiFileFormat.UNKNOWN_LENGTH,
MidiFileFormat.UNKNOWN_LENGTH, ntracks);
}
示例6: fillMetadata
@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);
}
}
示例7: getMidiFileFormatFromStream
private MidiFileFormat getMidiFileFormatFromStream(InputStream stream, int fileLength, SMFParser smfParser) throws InvalidMidiDataException, IOException {
int maxReadLength = 16;
int duration = MidiFileFormat.UNKNOWN_LENGTH;
DataInputStream dis;
if (stream instanceof DataInputStream) {
dis = (DataInputStream) stream;
} else {
dis = new DataInputStream(stream);
}
if (smfParser == null) {
dis.mark(maxReadLength);
} else {
smfParser.stream = dis;
}
int type;
int numtracks;
float divisionType;
int resolution;
try {
int magic = dis.readInt();
if( !(magic == MThd_MAGIC) ) {
// not MIDI
throw new InvalidMidiDataException("not a valid MIDI file");
}
// read header length
int bytesRemaining = dis.readInt() - 6;
type = dis.readShort();
numtracks = dis.readShort();
int timing = dis.readShort();
// decipher the timing code
if (timing > 0) {
// tempo based timing. value is ticks per beat.
divisionType = Sequence.PPQ;
resolution = timing;
} else {
// SMPTE based timing. first decipher the frame code.
int frameCode = -1 * (timing >> 8);
switch(frameCode) {
case 24:
divisionType = Sequence.SMPTE_24;
break;
case 25:
divisionType = Sequence.SMPTE_25;
break;
case 29:
divisionType = Sequence.SMPTE_30DROP;
break;
case 30:
divisionType = Sequence.SMPTE_30;
break;
default:
throw new InvalidMidiDataException("Unknown frame code: " + frameCode);
}
// now determine the timing resolution in ticks per frame.
resolution = timing & 0xFF;
}
if (smfParser != null) {
// remainder of this chunk
dis.skip(bytesRemaining);
smfParser.tracks = numtracks;
}
} finally {
// if only reading the file format, reset the stream
if (smfParser == null) {
dis.reset();
}
}
MidiFileFormat format = new MidiFileFormat(type, divisionType, resolution, fileLength, duration);
return format;
}