当前位置: 首页>>代码示例>>Java>>正文


Java AudioSystem.getAudioFileFormat方法代码示例

本文整理汇总了Java中javax.sound.sampled.AudioSystem.getAudioFileFormat方法的典型用法代码示例。如果您正苦于以下问题:Java AudioSystem.getAudioFileFormat方法的具体用法?Java AudioSystem.getAudioFileFormat怎么用?Java AudioSystem.getAudioFileFormat使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.sound.sampled.AudioSystem的用法示例。


在下文中一共展示了AudioSystem.getAudioFileFormat方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testSampleRate

import javax.sound.sampled.AudioSystem; //导入方法依赖的package包/类
private static boolean testSampleRate(float sampleRate) {
    boolean result = true;

    try {
        // create AudioInputStream with sample rate of 10000 Hz
        ByteArrayInputStream data = new ByteArrayInputStream(new byte[1]);
        AudioFormat format = new AudioFormat(sampleRate, 8, 1, true, true);
        AudioInputStream stream = new AudioInputStream(data, format, 1);

        // write to AIFF file
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        AudioSystem.write(stream, AudioFileFormat.Type.AIFF, outputStream);
        byte[] fileData = outputStream.toByteArray();
        InputStream inputStream = new ByteArrayInputStream(fileData);
        AudioFileFormat aff = AudioSystem.getAudioFileFormat(inputStream);
        if (! equals(sampleRate, aff.getFormat().getFrameRate())) {
            out("error for sample rate " + sampleRate);
            result = false;
        }
    } catch (Exception e) {
        out(e);
        out("Test NOT FAILED");
    }
    return result;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:26,代码来源:AiffSampleRate.java

示例2: initAudioInputStreamPart2

import javax.sound.sampled.AudioSystem; //导入方法依赖的package包/类
/**
 * Audio resources from File||URL||InputStream.
 *
 * @throws UnsupportedAudioFileException
 *             the unsupported audio file exception
 * @throws IOException
 *             Signals that an I/O exception has occurred.
 */
private void initAudioInputStreamPart2() throws UnsupportedAudioFileException , IOException {
	
	logger.info("Entered initAudioInputStreamPart->2\n");
	
	if (dataSource instanceof URL) {
		audioInputStream = AudioSystem.getAudioInputStream((URL) dataSource);
		audioFileFormat = AudioSystem.getAudioFileFormat((URL) dataSource);
		
	} else if (dataSource instanceof File) {
		audioInputStream = AudioSystem.getAudioInputStream((File) dataSource);
		audioFileFormat = AudioSystem.getAudioFileFormat((File) dataSource);
		
	} else if (dataSource instanceof InputStream) {
		audioInputStream = AudioSystem.getAudioInputStream((InputStream) dataSource);
		audioFileFormat = AudioSystem.getAudioFileFormat((InputStream) dataSource);
	}
	
	logger.info("Exited initAudioInputStreamPart->2\n");
	
}
 
开发者ID:goxr3plus,项目名称:java-stream-player,代码行数:29,代码来源:StreamPlayer.java

示例3: updateLength

import javax.sound.sampled.AudioSystem; //导入方法依赖的package包/类
/**
 * Description of the Method
 */
public void updateLength() {
    int i = getSelectedRow();
    if (i < 0) {
        return;
    }

    boolean changed = false;
    Vector<YassSong> sel = getSelectedSongs();
    for (Enumeration<YassSong> en = sel.elements(); en.hasMoreElements(); ) {
        YassSong s = en.nextElement();

        String dir = s.getDirectory();
        String mp3 = s.getMP3();

        File file = new File(dir + File.separator + mp3);
        if (file.exists()) {
            try {
                AudioFileFormat baseFileFormat = AudioSystem.getAudioFileFormat(file);
                if (baseFileFormat instanceof TAudioFileFormat) {
                    Map<?, ?> properties = baseFileFormat.properties();
                    Long dur = (Long) properties.get("duration");
                    long sec = Math.round(dur.longValue() / 1000000.0);
                    s.setLength(sec + "");
                    s.setSaved(false);
                    changed = true;
                }
            } catch (Exception e) {
            }
        }
    }
    if (changed) {
        setSaved(false);
    }
    repaint();
}
 
开发者ID:SarutaSan72,项目名称:Yass,代码行数:39,代码来源:YassSongList.java

示例4: updateAlbum

import javax.sound.sampled.AudioSystem; //导入方法依赖的package包/类
/**
 * Description of the Method
 */
public void updateAlbum() {
    int i = getSelectedRow();
    if (i < 0) {
        return;
    }

    boolean changed = false;
    Vector<YassSong> sel = getSelectedSongs();
    for (Enumeration<YassSong> en = sel.elements(); en.hasMoreElements(); ) {
        YassSong s = en.nextElement();

        String dir = s.getDirectory();
        String mp3 = s.getMP3();

        File file = new File(dir + File.separator + mp3);
        if (file.exists()) {
            try {
                AudioFileFormat baseFileFormat = AudioSystem.getAudioFileFormat(file);
                if (baseFileFormat instanceof TAudioFileFormat) {
                    Map<?, ?> properties = baseFileFormat.properties();
                    String a = (String) properties.get("album");
                    if (a != null && a.trim().length() > 0) {
                        s.setAlbum(a);
                        s.setSaved(false);
                        changed = true;
                    }
                }
            } catch (Exception e) {
            }
        }
    }
    if (changed) {
        setSaved(false);
    }
    repaint();
}
 
开发者ID:SarutaSan72,项目名称:Yass,代码行数:40,代码来源:YassSongList.java

示例5: updateYear

import javax.sound.sampled.AudioSystem; //导入方法依赖的package包/类
/**
 * Description of the Method
 */
public void updateYear() {
    int i = getSelectedRow();
    if (i < 0) {
        return;
    }

    boolean changed = false;
    Vector<YassSong> sel = getSelectedSongs();
    for (Enumeration<YassSong> en = sel.elements(); en.hasMoreElements(); ) {
        YassSong s = en.nextElement();

        String dir = s.getDirectory();
        String mp3 = s.getMP3();

        File file = new File(dir + File.separator + mp3);
        if (file.exists()) {
            try {
                AudioFileFormat baseFileFormat = AudioSystem.getAudioFileFormat(file);
                if (baseFileFormat instanceof TAudioFileFormat) {
                    Map<?, ?> properties = baseFileFormat.properties();
                    String y = (String) properties.get("year");
                    if (y != null && y.trim().length() > 0) {
                        s.setYear(y);
                        s.setSaved(false);
                        changed = true;
                    }
                }
            } catch (Exception e) {
            }
        }
    }
    if (changed) {
        setSaved(false);
    }
    repaint();
}
 
开发者ID:SarutaSan72,项目名称:Yass,代码行数:40,代码来源:YassSongList.java

示例6: test

import javax.sound.sampled.AudioSystem; //导入方法依赖的package包/类
private static void test(final byte[] buffer) throws IOException {
    final InputStream is = new ByteArrayInputStream(buffer);
    try {
        AudioSystem.getAudioFileFormat(is);
    } catch (UnsupportedAudioFileException ignored) {
        // Expected.
        return;
    }
    throw new RuntimeException("Test Failed");
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:11,代码来源:ReadersExceptions.java

示例7: testAFF

import javax.sound.sampled.AudioSystem; //导入方法依赖的package包/类
/**
 * Tests the {@code AudioFileFormat} fetched from the fake header.
 * <p>
 * Note that the frameLength and byteLength are stored as int which means
 * that {@code AudioFileFormat} will store the data above {@code MAX_INT} as
 * NOT_SPECIFIED.
 */
private static void testAFF(final byte[] type, final int rate,
                            final int channel, final long size)
        throws Exception {
    final byte[] header = createHeader(type, rate, channel, size);
    final ByteArrayInputStream fake = new ByteArrayInputStream(header);
    final AudioFileFormat aff = AudioSystem.getAudioFileFormat(fake);
    final AudioFormat format = aff.getFormat();

    if (aff.getType() != AudioFileFormat.Type.WAVE) {
        throw new RuntimeException("Error");
    }

    final long frameLength = size / format.getFrameSize();
    if (frameLength <= Integer.MAX_VALUE) {
        if (aff.getFrameLength() != frameLength) {
            System.err.println("Expected: " + frameLength);
            System.err.println("Actual: " + aff.getFrameLength());
            throw new RuntimeException();
        }
    } else {
        if (aff.getFrameLength() != AudioSystem.NOT_SPECIFIED) {
            System.err.println("Expected: " + AudioSystem.NOT_SPECIFIED);
            System.err.println("Actual: " + aff.getFrameLength());
            throw new RuntimeException();
        }
    }
    validateFormat(type[1], rate, channel, aff.getFormat());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:36,代码来源:RecognizeHugeWaveFiles.java

示例8: testAFF

import javax.sound.sampled.AudioSystem; //导入方法依赖的package包/类
/**
 * Tests the {@code AudioFileFormat} fetched from the fake header.
 * <p>
 * Note that the frameLength and byteLength are stored as int which means
 * that {@code AudioFileFormat} will store the data above {@code MAX_INT} as
 * NOT_SPECIFIED.
 */
private static void testAFF(final int[] type, final int rate,
                            final int channel, final long size)
        throws Exception {
    final byte[] header = createHeader(type, rate, channel, size);
    final ByteArrayInputStream fake = new ByteArrayInputStream(header);
    final AudioFileFormat aff = AudioSystem.getAudioFileFormat(fake);
    final AudioFormat format = aff.getFormat();

    if (aff.getType() != AudioFileFormat.Type.WAVE) {
        throw new RuntimeException("Error");
    }

    final long frameLength = size / format.getFrameSize();
    if (frameLength <= Integer.MAX_VALUE) {
        if (aff.getFrameLength() != frameLength) {
            System.err.println("Expected: " + frameLength);
            System.err.println("Actual: " + aff.getFrameLength());
            throw new RuntimeException();
        }
    } else {
        if (aff.getFrameLength() != AudioSystem.NOT_SPECIFIED) {
            System.err.println("Expected: " + AudioSystem.NOT_SPECIFIED);
            System.err.println("Actual: " + aff.getFrameLength());
            throw new RuntimeException();
        }
    }
    validateFormat(type[1], rate, channel, aff.getFormat());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:36,代码来源:RecognizeHugeWaveExtFiles.java

示例9: check

import javax.sound.sampled.AudioSystem; //导入方法依赖的package包/类
static void check(Object source) throws Exception {
     AudioFileFormat aff2 = null;
     if (source instanceof File) {
        aff2 = AudioSystem.getAudioFileFormat((File) source);
     }
     else if (source instanceof InputStream) {
        aff2 = AudioSystem.getAudioFileFormat((InputStream) source);
     }
     else if (source instanceof URL) {
        aff2 = AudioSystem.getAudioFileFormat((URL) source);
     } else throw new Exception("wrong source. Test FAILED");
     System.out.println("Got: "+aff2);
     if (aff2.getFormat().getSampleSizeInBits()==-1) {
        throw new Exception("wrong audio format. Test FAILED");
     }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:OpenWaveFile.java

示例10: testAS

import javax.sound.sampled.AudioSystem; //导入方法依赖的package包/类
private static void testAS(final byte[] buffer) throws IOException {
    // AudioSystem API
    final InputStream is = new ByteArrayInputStream(buffer);
    try {
        AudioSystem.getAudioFileFormat(is);
    } catch (UnsupportedAudioFileException ignored) {
        // Expected.
        return;
    }
    throw new RuntimeException("Test Failed");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:12,代码来源:ReadersExceptions.java

示例11: main

import javax.sound.sampled.AudioSystem; //导入方法依赖的package包/类
public static void main(final String[] args) throws Exception {
    final InputStream is = new ByteArrayInputStream(data);
    final AudioFileFormat aff = AudioSystem.getAudioFileFormat(is);
    System.out.println("AudioFileFormat: " + aff);
    try (AudioInputStream ais = AudioSystem.getAudioInputStream(is)) {
        System.out.println("AudioFormat: " + ais.getFormat());
    }
    System.out.println("new String(data) = " + new String(data));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:10,代码来源:RecognizeWaveExtensible.java

示例12: test

import javax.sound.sampled.AudioSystem; //导入方法依赖的package包/类
private static void test(final byte[] buffer)
        throws IOException, UnsupportedAudioFileException {
    final InputStream is = new ByteArrayInputStream(buffer);
    for (int i = 0; i < 10; ++i) {
        AudioSystem.getAudioFileFormat(is);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:8,代码来源:RepeatedFormatReader.java

示例13: testAFF

import javax.sound.sampled.AudioSystem; //导入方法依赖的package包/类
/**
 * Tests the {@code AudioFileFormat} fetched from the fake header.
 * <p>
 * Note that the frameLength and byteLength are stored as int which means
 * that {@code AudioFileFormat} will store the data above {@code MAX_INT} as
 * NOT_SPECIFIED.
 */
private static void testAFF(final byte bits, final int rate,
                            final int channel, final long frameLength)
        throws Exception {
    final byte[] header = createHeader(bits, rate, channel, frameLength);
    final ByteArrayInputStream fake = new ByteArrayInputStream(header);
    final AudioFileFormat aff = AudioSystem.getAudioFileFormat(fake);

    if (aff.getType() != AudioFileFormat.Type.AIFF) {
        throw new RuntimeException("Error");
    }

    if (frameLength <= Integer.MAX_VALUE) {
        if (aff.getFrameLength() != frameLength) {
            System.err.println("Expected: " + frameLength);
            System.err.println("Actual: " + aff.getFrameLength());
            throw new RuntimeException();
        }
    } else {
        if (aff.getFrameLength() != AudioSystem.NOT_SPECIFIED) {
            System.err.println("Expected: " + AudioSystem.NOT_SPECIFIED);
            System.err.println("Actual: " + aff.getFrameLength());
            throw new RuntimeException();
        }
    }
    validateFormat(bits, rate, channel, aff.getFormat());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:34,代码来源:RecognizeHugeAiffFiles.java

示例14: test

import javax.sound.sampled.AudioSystem; //导入方法依赖的package包/类
public static void test(byte[] file) throws Exception {
    InputStream inputStream = new ByteArrayInputStream(file);
    AudioFileFormat aff = AudioSystem.getAudioFileFormat(inputStream);

    if (aff.getFormat().getSampleSizeInBits() != 12) {
        throw new Exception("Wrong sample size. test FAILED");
    }
    if (aff.getFormat().getFrameSize() != 2) {
        throw new Exception("Wrong frame size. test FAILED");
    }
    if (aff.getFrameLength() != 100) {
        throw new Exception("Wrong file length. test FAILED");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:15,代码来源:Aiff12bit.java

示例15: test

import javax.sound.sampled.AudioSystem; //导入方法依赖的package包/类
public static void test(byte[] file) throws Exception {
    InputStream inputStream = new ByteArrayInputStream(file);
    AudioFileFormat aff = AudioSystem.getAudioFileFormat(inputStream);

    if (aff.getFrameLength() != 0) {
        throw new Exception("File length is "+aff.getFrameLength()+" instead of 0. test FAILED");
    }
    System.out.println(aff.getType()+" file length is 0.");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:10,代码来源:AuZeroLength.java


注:本文中的javax.sound.sampled.AudioSystem.getAudioFileFormat方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。