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:com.openbravo.pos.printer.TicketParser.java

@Override
public void endElement(String uri, String localName, String qName) throws SAXException {

    switch (m_iOutputType) {
    case OUTPUT_NONE:
        if ("play".equals(qName)) {
            try {
                AudioClip oAudio = Applet
                        .newAudioClip(getClass().getClassLoader().getResource(text.toString()));
                oAudio.play();//from w w  w.ja v  a 2s  .co  m
            } catch (Exception fnfe) {
                //throw new ResourceNotFoundException( fnfe.getMessage() );
            }
            text = null;
        }
        break;
    case OUTPUT_TICKET:
        if ("image".equals(qName)) {
            try {
                // BufferedImage image = ImageIO.read(getClass().getClassLoader().getResourceAsStream(m_sText.toString()));
                BufferedImage image = m_system.getResourceAsImage(text.toString());
                if (image != null) {
                    m_oOutputPrinter.printImage(image);
                }
            } catch (Exception fnfe) {
                //throw new ResourceNotFoundException( fnfe.getMessage() );
            }
            text = null;
        } else if ("barcode".equals(qName)) {
            m_oOutputPrinter.printBarCode(bctype, bcposition, text.toString());
            text = null;
        } else if ("text".equals(qName)) {
            if (m_iTextLength > 0) {
                switch (m_iTextAlign) {
                case DevicePrinter.ALIGN_RIGHT:
                    m_oOutputPrinter.printText(m_iTextStyle,
                            DeviceTicket.alignRight(text.toString(), m_iTextLength));
                    break;
                case DevicePrinter.ALIGN_CENTER:
                    m_oOutputPrinter.printText(m_iTextStyle,
                            DeviceTicket.alignCenter(text.toString(), m_iTextLength));
                    break;
                default: // DevicePrinter.ALIGN_LEFT
                    m_oOutputPrinter.printText(m_iTextStyle,
                            DeviceTicket.alignLeft(text.toString(), m_iTextLength));
                    break;
                }
            } else {
                m_oOutputPrinter.printText(m_iTextStyle, text.toString());
            }
            text = null;
        } else if ("line".equals(qName)) {
            m_oOutputPrinter.endLine();
        } else if ("ticket".equals(qName)) {
            m_oOutputPrinter.endReceipt();
            m_iOutputType = OUTPUT_NONE;
            m_oOutputPrinter = null;
        }
        break;
    case OUTPUT_DISPLAY:
        if ("line".equals(qName)) { // line 1 or 2 of the display
            if (m_sVisorLine1 == null) {
                m_sVisorLine1 = m_sVisorLine.toString();
            } else {
                m_sVisorLine2 = m_sVisorLine.toString();
            }
            m_sVisorLine = null;
        } else if ("line1".equals(qName)) { // linea 1 del visor
            m_sVisorLine1 = m_sVisorLine.toString();
            m_sVisorLine = null;
        } else if ("line2".equals(qName)) { // linea 2 del visor
            m_sVisorLine2 = m_sVisorLine.toString();
            m_sVisorLine = null;
        } else if ("text".equals(qName)) {
            if (m_iTextLength > 0) {
                switch (m_iTextAlign) {
                case DevicePrinter.ALIGN_RIGHT:
                    m_sVisorLine.append(DeviceTicket.alignRight(text.toString(), m_iTextLength));
                    break;
                case DevicePrinter.ALIGN_CENTER:
                    m_sVisorLine.append(DeviceTicket.alignCenter(text.toString(), m_iTextLength));
                    break;
                default: // DevicePrinter.ALIGN_LEFT
                    m_sVisorLine.append(DeviceTicket.alignLeft(text.toString(), m_iTextLength));
                    break;
                }
            } else {
                m_sVisorLine.append(text);
            }
            text = null;
        } else if ("display".equals(qName)) {
            m_printer.getDeviceDisplay().writeVisor(m_iVisorAnimation, m_sVisorLine1, m_sVisorLine2);
            m_iVisorAnimation = DeviceDisplayBase.ANIMATION_NULL;
            m_sVisorLine1 = null;
            m_sVisorLine2 = null;
            m_iOutputType = OUTPUT_NONE;
            m_oOutputPrinter = null;
        }
        break;
    case OUTPUT_FISCAL:
        if ("fiscalreceipt".equals(qName)) {
            m_printer.getFiscalPrinter().endReceipt();
            m_iOutputType = OUTPUT_NONE;
        } else if ("line".equals(qName)) {
            m_printer.getFiscalPrinter().printLine(text.toString(), m_dValue1, m_dValue2, attribute3);
            text = null;
        } else if ("message".equals(qName)) {
            m_printer.getFiscalPrinter().printMessage(text.toString());
            text = null;
        } else if ("total".equals(qName)) {
            m_printer.getFiscalPrinter().printTotal(text.toString(), m_dValue1);
            text = null;
        }
        break;
    }
}

From source file:org.gcaldaemon.core.notifier.GmailNotifierWindow.java

GmailNotifierWindow(String style, String sound) throws Exception {
    super(new Frame());

    // Load background
    int w = 300;//  www .j av  a  2s  .c o  m
    int h = 110;
    Toolkit toolkit = Toolkit.getDefaultToolkit();
    InputStream in;
    try {
        if (style.indexOf('.') == -1) {
            in = GmailNotifierWindow.class.getResourceAsStream(style + ".gif");
        } else {
            in = new FileInputStream(style);
        }
    } catch (Exception loadError) {
        log.error(loadError.getMessage(), loadError);
        in = GmailNotifierWindow.class.getResourceAsStream("default.gif");
    }
    ImageIO.setUseCache(false);
    background = ImageIO.read(in);
    in.close();
    Dimension size = toolkit.getScreenSize();
    setBounds((size.width - w) / 2, (size.height - h) / 2, w, h);
    metrics = getFontMetrics(PLAIN);

    // Set colors
    for (;;) {
        if (style.equals("metal")) {
            fromColor = Color.WHITE;
            break;
        }
        if (style.equals("green")) {
            titleColor = Color.GREEN;
            dateColor = new Color(0, 145, 0);
            break;
        }
        if (style.equals("blue")) {
            fromColor = Color.WHITE;
            titleColor = new Color(212, 235, 255);
            dateColor = titleColor;
            break;
        }
        if (style.equals("mail")) {
            titleColor = new Color(139, 128, 118);
            dateColor = titleColor;
            break;
        }
        break;
    }

    // Create offscreen buffer
    buffer = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
    offscreen = buffer.getGraphics();

    // Set notification sound
    if (sound == null || sound.equals("beep")) {
        clip = null;
    } else {
        try {
            URL url;
            if (sound.indexOf('.') == -1) {
                url = GmailNotifierWindow.class.getResource(sound + ".wav");
            } else {
                sound = sound.replace(File.separatorChar, '/');
                url = new URL("file", "", sound);
            }
            clip = Applet.newAudioClip(url);
        } catch (Exception soundError) {
            log.warn("Unable to load sound: " + sound, soundError);
            clip = null;
        }
    }

    // Init window
    setAlwaysOnTop(true);
    addMouseListener(this);
    addMouseMotionListener(this);
    validate();
}

From source file:org.trianacode.taskgraph.util.FileUtils.java

/**
 * Loads in a sound file from the specified internet location.
 *//*from  w ww .java 2s . c  o m*/
public static AudioClip getAudioClip(URL audioLoc) {
    System.out.println("Loading .... " + audioLoc);
    try {
        return Applet.newAudioClip(audioLoc);
    } catch (Exception e) {
        System.out.println("Couldn't load sound file " + audioLoc);
    }
    return null;
}

From source file:tvbrowser.extras.reminderplugin.ReminderPlugin.java

/**
 * Plays a sound.//from   www . j  a v a 2  s  .  c o m
 *
 * @param fileName
 *          The file name of the sound to play.
 * @return The sound Object.
 */
public static Object playSound(final String fileName) {
    try {
        if (StringUtils.endsWithIgnoreCase(fileName, ".mid")) {
            final Sequencer sequencer = MidiSystem.getSequencer();
            sequencer.open();

            final InputStream midiFile = new FileInputStream(fileName);
            sequencer.setSequence(MidiSystem.getSequence(midiFile));

            sequencer.start();

            new Thread("Reminder MIDI sequencer") {
                @Override
                public void run() {
                    setPriority(Thread.MIN_PRIORITY);
                    while (sequencer.isRunning()) {
                        try {
                            Thread.sleep(100);
                        } catch (Exception ee) {
                            // ignore
                        }
                    }

                    try {
                        sequencer.close();
                        midiFile.close();
                    } catch (Exception ee) {
                        // ignore
                    }
                }
            }.start();

            return sequencer;
        } else {
            final AudioInputStream ais = AudioSystem.getAudioInputStream(new File(fileName));

            final AudioFormat format = ais.getFormat();
            final DataLine.Info info = new DataLine.Info(SourceDataLine.class, format);

            if (AudioSystem.isLineSupported(info)) {
                final SourceDataLine line = (SourceDataLine) AudioSystem.getLine(info);

                line.open(format);
                line.start();

                new Thread("Reminder audio playing") {
                    private boolean stopped;

                    @Override
                    public void run() {
                        byte[] myData = new byte[1024 * format.getFrameSize()];
                        int numBytesToRead = myData.length;
                        int numBytesRead = 0;
                        int total = 0;
                        int totalToRead = (int) (format.getFrameSize() * ais.getFrameLength());
                        stopped = false;

                        line.addLineListener(new LineListener() {
                            public void update(LineEvent event) {
                                if (line != null && !line.isRunning()) {
                                    stopped = true;
                                    line.close();
                                    try {
                                        ais.close();
                                    } catch (Exception ee) {
                                        // ignore
                                    }
                                }
                            }
                        });

                        try {
                            while (total < totalToRead && !stopped) {
                                numBytesRead = ais.read(myData, 0, numBytesToRead);

                                if (numBytesRead == -1) {
                                    break;
                                }

                                total += numBytesRead;
                                line.write(myData, 0, numBytesRead);
                            }
                        } catch (Exception e) {
                        }

                        line.drain();
                        line.stop();
                    }
                }.start();

                return line;
            } else {
                URL url = new File(fileName).toURI().toURL();
                AudioClip clip = Applet.newAudioClip(url);
                clip.play();
            }
        }

    } catch (Exception e) {
        e.printStackTrace();
        if ((new File(fileName)).isFile()) {
            URL url;
            try {
                url = new File(fileName).toURI().toURL();
                AudioClip clip = Applet.newAudioClip(url);
                clip.play();
            } catch (MalformedURLException e1) {
            }
        } else {
            String msg = mLocalizer.msg("error.1", "Error loading reminder sound file!\n({0})", fileName);
            JOptionPane.showMessageDialog(UiUtilities.getBestDialogParent(MainFrame.getInstance()), msg,
                    Localizer.getLocalization(Localizer.I18N_ERROR), JOptionPane.ERROR_MESSAGE);
        }
    }
    return null;
}