Example usage for java.applet Applet newAudioClip

List of usage examples for java.applet Applet newAudioClip

Introduction

In this page you can find the example usage for java.applet Applet newAudioClip.

Prototype

public static final AudioClip newAudioClip(URL url) 

Source Link

Document

Get an audio clip from the given URL .

Usage

From source file:NoisyButton.java

public static void main(String[] args) throws Exception {
    java.io.File file = new java.io.File("bark.aiff");
    AudioClip sound = Applet.newAudioClip(file.toURL());
    sound.play();//  www.  j a v a  2s  . c  om
}

From source file:MainClass.java

public static void main(String[] args) {
    try {//from   w  w  w.j a v a 2 s  . co m
        URL url = new URL("file:youraudiofile.wav");
        AudioClip ac = Applet.newAudioClip(url);
        ac.play();

        System.out.println("Press any key to exit.");
        System.in.read();
        ac.stop();
    } catch (Exception e) {
        System.out.println(e);
    }
}

From source file:Play.java

public static void main(String args[]) {
    try {/*from ww w. j  a v a 2  s. co m*/
        // Loop
        URL url = new URL("http://java.sun.com/applets/other/Hangman/audio/whoopy.au");
        AudioClip clip = Applet.newAudioClip(url);
        clip.loop();
        Thread.sleep(5000);
        //Play
        File file = new File("bark.wav");
        clip = Applet.newAudioClip(file.toURL());
        clip.play();
        Thread.sleep(500);
        System.exit(0);
    } catch (InterruptedException e) {
    } catch (MalformedURLException e) {
    }
}

From source file:SoundPlay.java

public static void main(String[] av) {
    if (av.length == 0)
        main(defSounds);//from  w  w  w.j  av a 2 s  .com
    else
        for (int i = 0; i < av.length; i++) {
            System.out.println("Starting " + av[i]);
            try {
                URL snd = new URL(av[i]);
                // open to see if works or throws exception, close to free
                // fd's
                // snd.openConnection().getInputStream().close();
                Applet.newAudioClip(snd).play();
            } catch (Exception e) {
                System.err.println(e);
            }
        }
    // With this call, program exits before/during play.
    // Without it, on some versions, program hangs forever after play.
    // System.exit(0);
}

From source file:core.PlanC.java

/**
 * inicio de aplicacion/*w ww  . j av a2  s.  c o  m*/
 * 
 * @param arg - argumentos de entrada
 */
public static void main(String[] args) {

    // user.name

    /*
     * Properties prp = System.getProperties(); System.out.println(getWmicValue("bios", "SerialNumber"));
     * System.out.println(getWmicValue("cpu", "SystemName"));
     */

    try {
        // log
        // -Djava.util.logging.SimpleFormatter.format='%1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS %4$s %2$s %5$s%6$s%n'
        // System.setProperty("java.util.logging.SimpleFormatter.format",
        // "%1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS %4$s %2$s %5$s%6$s%n");
        System.setProperty("java.util.logging.SimpleFormatter.format",
                "%1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS %5$s%6$s%n");

        FileHandler fh = new FileHandler(LOG_FILE);
        fh.setFormatter(new SimpleFormatter());
        fh.setLevel(Level.INFO);
        ConsoleHandler ch = new ConsoleHandler();
        ch.setFormatter(new SimpleFormatter());
        ch.setLevel(Level.INFO);
        logger = Logger.getLogger("");
        Handler[] hs = logger.getHandlers();
        for (int x = 0; x < hs.length; x++) {
            logger.removeHandler(hs[x]);
        }
        logger.addHandler(fh);
        logger.addHandler(ch);
        // point apache log to this log
        System.setProperty("org.apache.commons.logging.Log", Jdk14Logger.class.getName());

        TPreferences.init();
        TStringUtils.init();

        Font fo = Font.createFont(Font.TRUETYPE_FONT, TResourceUtils.getFile("Dosis-Light.ttf"));
        GraphicsEnvironment.getLocalGraphicsEnvironment().registerFont(fo);
        fo = Font.createFont(Font.TRUETYPE_FONT, TResourceUtils.getFile("Dosis-Medium.ttf"));
        GraphicsEnvironment.getLocalGraphicsEnvironment().registerFont(fo);
        fo = Font.createFont(Font.TRUETYPE_FONT, TResourceUtils.getFile("AERO_ITALIC.ttf"));
        GraphicsEnvironment.getLocalGraphicsEnvironment().registerFont(fo);

        SwingTimerTimingSource ts = new SwingTimerTimingSource();
        AnimatorBuilder.setDefaultTimingSource(ts);
        ts.init();

        // parse app argument parameters and append to tpreferences to futher uses
        for (String arg : args) {
            String[] kv = arg.split("=");
            TPreferences.setProperty(kv[0], kv[1]);
        }
        RUNNING_MODE = TPreferences.getProperty("runningMode", RM_NORMAL);

        newMsg = Applet.newAudioClip(TResourceUtils.getURL("newMsg.wav"));

    } catch (Exception e) {
        SystemLog.logException1(e, true);
    }

    // pass icon from metal to web look and feel
    Icon i1 = UIManager.getIcon("OptionPane.errorIcon");
    Icon i2 = UIManager.getIcon("OptionPane.informationIcon");
    Icon i3 = UIManager.getIcon("OptionPane.questionIcon");
    Icon i4 = UIManager.getIcon("OptionPane.warningIcon");
    // Object fcui = UIManager.get("FileChooserUI");
    // JFileChooser fc = new JFileChooser();

    WebLookAndFeel.install();
    // WebLookAndFeel.setDecorateFrames(true);
    // WebLookAndFeel.setDecorateDialogs(true);

    UIManager.put("OptionPane.errorIcon", i1);
    UIManager.put("OptionPane.informationIcon", i2);
    UIManager.put("OptionPane.questionIcon", i3);
    UIManager.put("OptionPane.warningIcon", i4);
    // UIManager.put("TFileChooserUI", fcui);

    // warm up the IDW.
    // in my computer, some weird error ocurr if i don't execute this preload.
    new RootWindow(null);

    frame = new TWebFrame();
    frame.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            Exit.shutdown();
        }
    });

    if (RUNNING_MODE.equals(RM_NORMAL)) {
        initEnviorement();
    }
    if (RUNNING_MODE.equals(RM_CONSOLE)) {
        initConsoleEnviorement();
    }

    if (RUNNING_MODE.equals(ONE_TASK)) {
        String cln = TPreferences.getProperty("taskName", "*TaskNotFound");
        PlanC.logger.log(Level.INFO, "OneTask parameter found in .properties. file Task name = " + cln);
        try {
            Class cls = Class.forName(cln);
            Object dobj = cls.newInstance();
            // new class must be extends form AbstractExternalTask
            TTaskManager.executeTask((Runnable) dobj);
            return;
        } catch (Exception e) {
            PlanC.logger.log(Level.SEVERE, e.getMessage(), e);
            Exit.shutdown();
        }
    }
}

From source file:MainClass.java

public MainClass() {
    this.setSize(400, 400);
    this.setTitle("Mouse Clicker");
    this.addMouseListener(new Clicker());

    URL urlClick = MainClass.class.getResource("hit.wav");
    click = Applet.newAudioClip(urlClick);

    this.setVisible(true);
}

From source file:MinAppletviewer.java

public AudioClip getAudioClip(URL url) {
    return Applet.newAudioClip(url);
}

From source file:de.tor.tribes.util.ClipboardWatch.java

private synchronized void playNotification() {
    if (!Boolean.parseBoolean(GlobalOptions.getProperty("clipboard.notification"))) {
        return;/*from   w ww  .  ja  v a2s  .  c o m*/
    }

    Timer t = new Timer("ClipboardNotification", true);
    t.schedule(new TimerTask() {
        @Override
        public void run() {
            if (clip != null) {//reset clip
                clip.stop();
                clip.setMicrosecondPosition(0);
            }
            if (ac != null) {
                ac.stop();
            }

            try {
                if (org.apache.commons.lang.SystemUtils.IS_OS_WINDOWS) {
                    if (clip == null) {
                        clip = AudioSystem.getClip();
                        AudioInputStream inputStream = AudioSystem
                                .getAudioInputStream(ClockFrame.class.getResourceAsStream("/res/Ding.wav"));
                        clip.open(inputStream);
                    }
                    clip.start();
                } else {
                    if (ac == null) {
                        ac = Applet.newAudioClip(ClockFrame.class.getResource("/res/Ding.wav"));
                    }
                    ac.play();
                }
            } catch (Exception e) {
                logger.error("Failed to play notification", e);
            }
        }
    }, 0);
}

From source file:AccessoryFileChooser.java

public void setCurrentClip(File f) {
    if (currentClip != null) {
        currentClip.stop();//from  w  w w.  j  a v  a2  s  .  c om
    }
    // Make sure we have a real file, otherwise, disable the buttons
    if ((f == null) || (f.getName() == null)) {
        fileLabel.setText("no audio selected");
        playButton.setEnabled(false);
        stopButton.setEnabled(false);
        return;
    }

    // Ok, seems the audio file is real, so load it and enable the buttons
    String name = f.getName();
    if (name.equals(currentName)) {
        // Same clip they just loaded...make sure the player is enabled
        fileLabel.setText(name);
        playButton.setEnabled(true);
        stopButton.setEnabled(true);
        return;
    }
    currentName = name;
    try {
        URL u = new URL("file:///" + f.getAbsolutePath());
        currentClip = Applet.newAudioClip(u);
    } catch (Exception e) {
        e.printStackTrace();
        currentClip = null;
        fileLabel.setText("Error loading clip.");
    }
    fileLabel.setText(name);
    playButton.setEnabled(true);
    stopButton.setEnabled(true);
}

From source file:de.tor.tribes.ui.windows.ClockFrame.java

public synchronized void playSound(String pSound) {
    Clip clip = null;/* w w  w .  ja v a  2s  .  com*/
    AudioClip ac = null;
    try {
        if (org.apache.commons.lang3.SystemUtils.IS_OS_WINDOWS) {
            clip = AudioSystem.getClip();
            BufferedInputStream bin = new BufferedInputStream(
                    ClockFrame.class.getResourceAsStream("/res/" + pSound + ".wav"));
            AudioInputStream inputStream = AudioSystem.getAudioInputStream(bin);
            clip.open(inputStream);
            clip.start();
        } else {
            ac = Applet.newAudioClip(ClockFrame.class.getResource("/res/" + pSound + ".wav"));
            ac.play();
        }
    } catch (Exception e) {
        logger.error("Failed to play sound", e);
    }
    try {
        Thread.sleep(2500);
    } catch (Exception ignored) {
    }

    try {
        if (clip != null) {
            clip.stop();
            clip.flush();
            clip = null;
        }

        if (ac != null) {
            ac.stop();
            ac = null;
        }
    } catch (Exception ignored) {
    }
}