Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/sun/applet/AppletAudioClip.java
38829 views
/*1* Copyright (c) 1995, 2003, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.applet;2627import java.io.IOException;28import java.io.InputStream;29import java.io.ByteArrayInputStream;30import java.net.URL;31import java.net.URLConnection;32import java.applet.AudioClip;3334import com.sun.media.sound.JavaSoundAudioClip;353637/**38* Applet audio clip;39*40* @author Arthur van Hoff, Kara Kytle41*/4243public class AppletAudioClip implements AudioClip {4445// url that this AudioClip is based on46private URL url = null;4748// the audio clip implementation49private AudioClip audioClip = null;5051boolean DEBUG = false /*true*/;5253/**54* Constructs an AppletAudioClip from an URL.55*/56public AppletAudioClip(URL url) {5758// store the url59this.url = url;6061try {62// create a stream from the url, and use it63// in the clip.64InputStream in = url.openStream();65createAppletAudioClip(in);6667} catch (IOException e) {68/* just quell it */69if (DEBUG) {70System.err.println("IOException creating AppletAudioClip" + e);71}72}73}7475/**76* Constructs an AppletAudioClip from a URLConnection.77*/78public AppletAudioClip(URLConnection uc) {7980try {81// create a stream from the url, and use it82// in the clip.83createAppletAudioClip(uc.getInputStream());8485} catch (IOException e) {86/* just quell it */87if (DEBUG) {88System.err.println("IOException creating AppletAudioClip" + e);89}90}91}929394/**95* For constructing directly from Jar entries, or any other96* raw Audio data. Note that the data provided must include the format97* header.98*/99public AppletAudioClip(byte [] data) {100101try {102103// construct a stream from the byte array104InputStream in = new ByteArrayInputStream(data);105106createAppletAudioClip(in);107108} catch (IOException e) {109/* just quell it */110if (DEBUG) {111System.err.println("IOException creating AppletAudioClip " + e);112}113}114}115116117/*118* Does the real work of creating an AppletAudioClip from an InputStream.119* This function is used by both constructors.120*/121void createAppletAudioClip(InputStream in) throws IOException {122123try {124audioClip = new JavaSoundAudioClip(in);125} catch (Exception e3) {126// no matter what happened, we throw an IOException to avoid changing the interfaces....127throw new IOException("Failed to construct the AudioClip: " + e3);128}129}130131132public synchronized void play() {133134if (audioClip != null)135audioClip.play();136}137138139public synchronized void loop() {140141if (audioClip != null)142audioClip.loop();143}144145public synchronized void stop() {146147if (audioClip != null)148audioClip.stop();149}150}151152153