Loads a Audio clip from the resource directory. - Java javax.sound.sampled

Java examples for javax.sound.sampled:Audio

Description

Loads a Audio clip from the resource directory.

Demo Code


//package com.java2s;
import java.applet.Applet;
import java.applet.AudioClip;

import java.net.URL;

public class Main {
    public static void main(String[] argv) throws Exception {
        String filename = "java2s.com";
        System.out.println(loadClip(filename));
    }/*from www  .j a  v  a  2  s . c  o  m*/

    private static String resources = "";
    private static ClassLoader loader;

    /**
     * Loads a clip from the resource directory.
     * 
     * @param filename
     *        => The name of the file in the resource directory.
     */
    public static AudioClip loadClip(String filename) throws Exception {
        URL url = loader.getResource(resources + filename);
        return Applet.newAudioClip(url);
    }
}

Related Tutorials