java—即使在将vorbisspi添加到类路径之后,也不支持音频文件格式

eiee3dmh  于 2021-06-26  发布在  Java
关注(0)|答案(0)|浏览(200)

伙计们正在尝试读取不同的音频格式的帮助下,声音spi。我已经在类路径中添加了声音spi,但是由于某些原因它没有被使用/或者没有被检测到。
am使用VORBISPI并且am获取不支持的音频文件格式错误。
这是我的毕业证书

buildscript{
    dependencies {

       // classpath // https://mvnrepository.com/artifact/com.github.trilarion/vorbis-support
       classpath group: 'com.github.trilarion', name: 'vorbis-support', version: '1.1.0'

    }
}

plugins {
    id 'java'

}

group 'org.example'
version '1.0-SNAPSHOT'

repositories {
    mavenCentral()
}

dependencies {

}

test {
    useJUnitPlatform()
}

这是播放音频文件的类

import javax.sound.sampled.*;
import java.io.File;
import java.io.IOException;
import java.util.Scanner;

public class Player implements LineListener {

    boolean playCompleted;

    public void play(String audioFilePath) {
        File audioFile = new File(audioFilePath);

        try {
            AudioInputStream audioStream = AudioSystem.getAudioInputStream(audioFile);

            AudioFormat format = audioStream.getFormat();

            DataLine.Info info = new DataLine.Info(Clip.class, format);

            Clip audioClip = (Clip) AudioSystem.getLine(info);

            audioClip.addLineListener(this);

            audioClip.open(audioStream);

            audioClip.start();

            while (!playCompleted) {
                // wait for the playback completes
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException ex) {
                    ex.printStackTrace();
                }
            }

            audioClip.close();

        } catch (UnsupportedAudioFileException ex) {
            System.out.println("The specified audio file is not supported.");
            ex.printStackTrace();
        } catch (LineUnavailableException ex) {
            System.out.println("Audio line for playing back is unavailable.");
            ex.printStackTrace();
        } catch (IOException ex) {
            System.out.println("Error playing the audio file.");
            ex.printStackTrace();
        }

    }
    @Override
    public void update(LineEvent event) {
        LineEvent.Type type = event.getType();

        if (type == LineEvent.Type.START) {
            System.out.println("Playback started.");

        } else if (type == LineEvent.Type.STOP) {
            playCompleted = true;
            System.out.println("Playback completed.");
        }

    }
}

当试图读取.ogg、.ogx、.opus时,它抛出一个错误,表示它的格式不受支持

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题