1 year ago

#132007

test-img

Fluke

How to fix UnsupportedAudioFileException

I cannot play the audio file. I am making a java game and face this problem. I am coding on Eclipse. I have used .wav 16 bits audio file. I have tried to reinstall eclipse program and it still doesn't work.

Error -

javax.sound.sampled.UnsupportedAudioFileException: URL of unsupported format

How I encoded wav files -

enter image description here

enter image description here

import java.net.URL;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;

public class Sound {
    
    Clip clip;
    URL soundURL[] = new URL[30];
    
    public Sound() {
        
        soundURL[0] = getClass().getResource("/Music.wav");
    }
    
    public void setFile(int i) {
        
        try {
            AudioInputStream ais = AudioSystem.getAudioInputStream(soundURL[i]);
            clip = AudioSystem.getClip();
            clip.open(ais);
            
        }catch(Exception e) {
            e.printStackTrace();
        }
        
    }
    
    public void play() {
        clip.start();
    }
    
    public void loop() {
        clip.loop(Clip.LOOP_CONTINUOUSLY);
    }
    
    public void stop() {
        clip.stop();
    }
    

}

java

eclipse

url

audio

javasound

0 Answers

Your Answer

Accepted video resources