diff -r 38b0d0abca49 -r 02b8ba539ccb jdk/src/share/classes/sun/audio/AudioPlayer.java --- a/jdk/src/share/classes/sun/audio/AudioPlayer.java Mon Aug 04 15:33:48 2014 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,186 +0,0 @@ -/* - * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package sun.audio; - -import java.io.InputStream; -import java.security.AccessController; -import java.security.PrivilegedAction; - - -/** - * This class provides an interface to play audio streams. - * - * To play an audio stream use: - *
- *      AudioPlayer.player.start(audiostream);
- * 
- * To stop playing an audio stream use: - *
- *      AudioPlayer.player.stop(audiostream);
- * 
- * To play an audio stream from a URL use: - *
- *      AudioStream audiostream = new AudioStream(url.openStream());
- *      AudioPlayer.player.start(audiostream);
- * 
- * To play a continuous sound you first have to - * create an AudioData instance and use it to construct a - * ContinuousAudioDataStream. - * For example: - *
- *      AudioData data = new AudioStream(url.openStream()).getData();
- *      ContinuousAudioDataStream audiostream = new ContinuousAudioDataStream(data);
- *      AudioPlayer.player.start(audiostream);
- * 
- * - * @see AudioData - * @see AudioDataStream - * @see AudioDevice - * @see AudioStream - * @author Arthur van Hoff, Thomas Ball - */ - -public final class AudioPlayer extends Thread { - - private final AudioDevice devAudio; - private final static boolean DEBUG = false /*true*/; - - /** - * The default audio player. This audio player is initialized - * automatically. - */ - public static final AudioPlayer player = getAudioPlayer(); - - private static ThreadGroup getAudioThreadGroup() { - - if(DEBUG) { System.out.println("AudioPlayer.getAudioThreadGroup()"); } - ThreadGroup g = currentThread().getThreadGroup(); - while ((g.getParent() != null) && - (g.getParent().getParent() != null)) { - g = g.getParent(); - } - return g; - } - - /** - * Create an AudioPlayer thread in a privileged block. - */ - - private static AudioPlayer getAudioPlayer() { - - if(DEBUG) { System.out.println("> AudioPlayer.getAudioPlayer()"); } - PrivilegedAction action = new PrivilegedAction() { - public AudioPlayer run() { - AudioPlayer t = new AudioPlayer(); - t.setPriority(MAX_PRIORITY); - t.setDaemon(true); - t.start(); - return t; - } - }; - return AccessController.doPrivileged(action); - } - - /** - * Construct an AudioPlayer. - */ - private AudioPlayer() { - - super(getAudioThreadGroup(), "Audio Player"); - if(DEBUG) { System.out.println("> AudioPlayer private constructor"); } - devAudio = AudioDevice.device; - devAudio.open(); - if(DEBUG) { System.out.println("< AudioPlayer private constructor completed"); } - } - - - /** - * Start playing a stream. The stream will continue to play - * until the stream runs out of data, or it is stopped. - * @see AudioPlayer#stop - */ - public synchronized void start(InputStream in) { - - if(DEBUG) { - System.out.println("> AudioPlayer.start"); - System.out.println(" InputStream = " + in); - } - devAudio.openChannel(in); - notify(); - if(DEBUG) { - System.out.println("< AudioPlayer.start completed"); - } - } - - /** - * Stop playing a stream. The stream will stop playing, - * nothing happens if the stream wasn't playing in the - * first place. - * @see AudioPlayer#start - */ - public synchronized void stop(InputStream in) { - - if(DEBUG) { - System.out.println("> AudioPlayer.stop"); - } - - devAudio.closeChannel(in); - if(DEBUG) { - System.out.println("< AudioPlayer.stop completed"); - } - } - - /** - * Main mixing loop. This is called automatically when the AudioPlayer - * is created. - */ - public void run() { - - // $$jb: 06.24.99: With the JS API, mixing is no longer done by AudioPlayer - // or AudioDevice ... it's done by the API itself, so this bit of legacy - // code does nothing. - // $$jb: 10.21.99: But it appears that some legacy applications - // check to see if this thread is alive or not, so we need to spin here. - - devAudio.play(); - if(DEBUG) { - System.out.println("AudioPlayer mixing loop."); - } - while(true) { - try{ - Thread.sleep(5000); - //wait(); - } catch(Exception e) { - break; - // interrupted - } - } - if(DEBUG) { - System.out.println("AudioPlayer exited."); - } - - } - }