當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。