load Sound File from URL - Java Applet

Java examples for Applet:AudioClip

Description

load Sound File from URL

Demo Code


import java.applet.Applet;
import java.applet.AudioClip;

public class Main{
    public static void main(String[] argv) throws Exception{
        String s = "java2s.com";
        System.out.println(loadSound(s));
    }/*from   w w w  .j  av a  2 s.c o  m*/
    public static AudioClip loadSound(String s) {
        ClassLoader loader = AudioUtility.class.getClassLoader();

        try {
            //System.out.println(Applet.newAudioClip((loader.getResource(s)).toURI().toURL()));
            return Applet.newAudioClip((loader.getResource(s)).toURI()
                    .toURL());
        } catch (Exception e) {
            System.err.println("Error load sound " + s);
        }
        return null;
    }
}

Related Tutorials