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


Java AudioFileWriter类代码示例

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


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

示例1: getProviders

import javax.sound.sampled.spi.AudioFileWriter; //导入依赖的package包/类
/**
 * Obtains a List containing installed instances of the providers for the
 * requested service. The returned List is immutable.
 *
 * @param serviceClass The type of providers requested. This should be one
 *                     of AudioFileReader.class, AudioFileWriter.class,
 *                     FormatConversionProvider.class, MixerProvider.class,
 *                     MidiDeviceProvider.class, MidiFileReader.class,
 *                     MidiFileWriter.class or SoundbankReader.class.
 *
 * @return A List of providers of the requested type. This List is
 *         immutable.
 */
public static List<?> getProviders(final Class<?> serviceClass) {
    final List<?> providers;
    if (!MixerProvider.class.equals(serviceClass)
            && !FormatConversionProvider.class.equals(serviceClass)
            && !AudioFileReader.class.equals(serviceClass)
            && !AudioFileWriter.class.equals(serviceClass)
            && !MidiDeviceProvider.class.equals(serviceClass)
            && !SoundbankReader.class.equals(serviceClass)
            && !MidiFileWriter.class.equals(serviceClass)
            && !MidiFileReader.class.equals(serviceClass)) {
        providers = new ArrayList<>(0);
    } else {
        providers = JSSecurityManager.getProviders(serviceClass);
    }
    return Collections.unmodifiableList(providers);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:30,代码来源:JDK13Services.java

示例2: getAudioFileTypes

import javax.sound.sampled.spi.AudioFileWriter; //导入依赖的package包/类
/**
 * Obtains the file types for which file writing support is provided by the system.
 * @return array of unique file types.  If no file types are supported,
 * an array of length 0 is returned.
 */
public static AudioFileFormat.Type[] getAudioFileTypes() {
    List providers = getAudioFileWriters();
    Set returnTypesSet = new HashSet();

    for(int i=0; i < providers.size(); i++) {
        AudioFileWriter writer = (AudioFileWriter) providers.get(i);
        AudioFileFormat.Type[] fileTypes = writer.getAudioFileTypes();
        for(int j=0; j < fileTypes.length; j++) {
            returnTypesSet.add(fileTypes[j]);
        }
    }
    AudioFileFormat.Type returnTypes[] = (AudioFileFormat.Type[])
        returnTypesSet.toArray(new AudioFileFormat.Type[0]);
    return returnTypes;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:21,代码来源:AudioSystem.java

示例3: write

import javax.sound.sampled.spi.AudioFileWriter; //导入依赖的package包/类
/**
 * Writes a stream of bytes representing an audio file of the specified file type
 * to the output stream provided.  Some file types require that
 * the length be written into the file header; such files cannot be written from
 * start to finish unless the length is known in advance.  An attempt
 * to write a file of such a type will fail with an IOException if the length in
 * the audio file type is <code>AudioSystem.NOT_SPECIFIED</code>.
 *
 * @param stream the audio input stream containing audio data to be
 * written to the file
 * @param fileType the kind of audio file to write
 * @param out the stream to which the file data should be written
 * @return the number of bytes written to the output stream
 * @throws IOException if an input/output exception occurs
 * @throws IllegalArgumentException if the file type is not supported by
 * the system
 * @see #isFileTypeSupported
 * @see     #getAudioFileTypes
 */
public static int write(AudioInputStream stream, AudioFileFormat.Type fileType,
                        OutputStream out) throws IOException {

    List providers = getAudioFileWriters();
    int bytesWritten = 0;
    boolean flag = false;

    for(int i=0; i < providers.size(); i++) {
        AudioFileWriter writer = (AudioFileWriter) providers.get(i);
        try {
            bytesWritten = writer.write( stream, fileType, out ); // throws IOException
            flag = true;
            break;
        } catch (IllegalArgumentException e) {
            // thrown if this provider cannot write the sequence, try the next
            continue;
        }
    }
    if(!flag) {
        throw new IllegalArgumentException("could not write audio file: file type not supported: " + fileType);
    } else {
        return bytesWritten;
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:44,代码来源:AudioSystem.java

示例4: getAudioFileTypes

import javax.sound.sampled.spi.AudioFileWriter; //导入依赖的package包/类
/**
 * Obtains the file types for which file writing support is provided by the
 * system.
 *
 * @return array of unique file types. If no file types are supported, an
 *         array of length 0 is returned.
 */
public static AudioFileFormat.Type[] getAudioFileTypes() {
    List<AudioFileWriter> providers = getAudioFileWriters();
    Set<AudioFileFormat.Type> returnTypesSet = new HashSet<>();

    for(int i=0; i < providers.size(); i++) {
        AudioFileWriter writer = providers.get(i);
        AudioFileFormat.Type[] fileTypes = writer.getAudioFileTypes();
        for(int j=0; j < fileTypes.length; j++) {
            returnTypesSet.add(fileTypes[j]);
        }
    }
    AudioFileFormat.Type returnTypes[] =
        returnTypesSet.toArray(new AudioFileFormat.Type[0]);
    return returnTypes;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:23,代码来源:AudioSystem.java

示例5: write

import javax.sound.sampled.spi.AudioFileWriter; //导入依赖的package包/类
/**
 * Writes a stream of bytes representing an audio file of the specified file
 * type to the external file provided.
 *
 * @param  stream the audio input stream containing audio data to be written
 *         to the file
 * @param  fileType the kind of audio file to write
 * @param  out the external file to which the file data should be written
 * @return the number of bytes written to the file
 * @throws IOException if an I/O exception occurs
 * @throws IllegalArgumentException if the file type is not supported by the
 *         system
 * @throws NullPointerException if {@code stream} or {@code fileType} or
 *         {@code out} are {@code null}
 * @see #isFileTypeSupported
 * @see #getAudioFileTypes
 */
public static int write(final AudioInputStream stream,
                        final AudioFileFormat.Type fileType,
                        final File out) throws IOException {
    Objects.requireNonNull(stream);
    Objects.requireNonNull(fileType);
    Objects.requireNonNull(out);

    for (final AudioFileWriter writer : getAudioFileWriters()) {
        try {
            return writer.write(stream, fileType, out);
        } catch (final IllegalArgumentException ignored) {
            // thrown if this provider cannot write the stream, try next
        }
    }
    throw new IllegalArgumentException(
            "could not write audio file: file type not supported: "
                    + fileType);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:36,代码来源:AudioSystem.java

示例6: testAfterSaveToFile

import javax.sound.sampled.spi.AudioFileWriter; //导入依赖的package包/类
/**
 * Verifies the frame length after the stream was saved/read to/from file.
 */
private static void testAfterSaveToFile(final AudioFileWriter afw,
                                        final AudioFileFormat.Type type,
                                        AudioInputStream ais)
        throws IOException {
    final File temp = File.createTempFile("sound", ".tmp");
    try {
        afw.write(ais, type, temp);
        ais = AudioSystem.getAudioInputStream(temp);
        final long frameLength = ais.getFrameLength();
        ais.close();
        validate(frameLength);
    } catch (IllegalArgumentException | UnsupportedAudioFileException
            ignored) {
    } finally {
        Files.delete(Paths.get(temp.getAbsolutePath()));
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:FrameLengthAfterConversion.java

示例7: testAfterSaveToFile

import javax.sound.sampled.spi.AudioFileWriter; //导入依赖的package包/类
/**
 * Verifies the frame length after the stream was saved/read to/from file.
 */
private static void testAfterSaveToFile(final AudioFileWriter afw,
                                        final AudioFileFormat.Type type,
                                        AudioInputStream ais) {
    try {
        final File temp = File.createTempFile("sound", ".tmp");
        temp.deleteOnExit();
        afw.write(ais, type, temp);
        ais = AudioSystem.getAudioInputStream(temp);
        final long frameLength = ais.getFrameLength();
        ais.close();
        temp.delete();
        validate(frameLength);
    } catch (IllegalArgumentException | UnsupportedAudioFileException
            | IOException ignored) {
    }
}
 
开发者ID:campolake,项目名称:openjdk9,代码行数:20,代码来源:FrameLengthAfterConversion.java


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