unsupported audio file format even after adding vorbisspi to classpath

299 Views Asked by At

guys am trying to read different audio formats with help of sound SPI. I have added sound SPI to classpath but still for some reason its not being used/or not detected.

Am using vorbisspi and am getting unsupported audio file format error.

here is my gradle

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()
}

here is the class which plays audio file

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.");
        }

    }
}

when trying to read .ogg,.ogx,.opus it throws error saying that its unsupported format

0

There are 0 best solutions below