< prev index next >

src/java.desktop/share/classes/com/sun/media/sound/JavaSoundAudioClip.java

Print this page

        

*** 1,7 **** /* ! * Copyright (c) 1999, 2016, 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 --- 1,7 ---- /* ! * Copyright (c) 1999, 2018, 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
*** 28,37 **** --- 28,39 ---- import java.applet.AudioClip; import java.io.BufferedInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; + import java.net.URL; + import java.net.URLConnection; import javax.sound.midi.InvalidMidiDataException; import javax.sound.midi.MetaEventListener; import javax.sound.midi.MetaMessage; import javax.sound.midi.MidiFileFormat;
*** 74,83 **** --- 76,86 ---- private DataPusher datapusher = null; private Sequencer sequencer = null; private Sequence sequence = null; private boolean sequencerloop = false; + private volatile boolean success; /** * used for determining how many samples is the * threshhold between playing as a Clip and streaming * from the file.
*** 89,104 **** */ private static final long CLIP_THRESHOLD = 1048576; //private final static long CLIP_THRESHOLD = 1; private static final int STREAM_BUFFER_SIZE = 1024; ! public JavaSoundAudioClip(InputStream in) throws IOException { if (DEBUG || Printer.debug)Printer.debug("JavaSoundAudioClip.<init>"); BufferedInputStream bis = new BufferedInputStream(in, STREAM_BUFFER_SIZE); bis.mark(STREAM_BUFFER_SIZE); - boolean success = false; try { AudioInputStream as = AudioSystem.getAudioInputStream(bis); // load the stream data into memory success = loadAudioData(as); --- 92,126 ---- */ private static final long CLIP_THRESHOLD = 1048576; //private final static long CLIP_THRESHOLD = 1; private static final int STREAM_BUFFER_SIZE = 1024; ! public static JavaSoundAudioClip create(final URLConnection uc) { ! JavaSoundAudioClip clip = new JavaSoundAudioClip(); ! try { ! clip.init(uc.getInputStream()); ! } catch (final Exception ignored) { ! // AudioClip will be no-op if some exception will occurred ! } ! return clip; ! } ! ! public static JavaSoundAudioClip create(final URL url) { ! JavaSoundAudioClip clip = new JavaSoundAudioClip(); ! try { ! clip.init(url.openStream()); ! } catch (final Exception ignored) { ! // AudioClip will be no-op if some exception will occurred ! } ! return clip; ! } ! ! private void init(InputStream in) throws IOException { if (DEBUG || Printer.debug)Printer.debug("JavaSoundAudioClip.<init>"); BufferedInputStream bis = new BufferedInputStream(in, STREAM_BUFFER_SIZE); bis.mark(STREAM_BUFFER_SIZE); try { AudioInputStream as = AudioSystem.getAudioInputStream(bis); // load the stream data into memory success = loadAudioData(as);
*** 118,139 **** success = createSequencer(bis); } catch (InvalidMidiDataException e1) { success = false; } } - if (!success) { - throw new IOException("Unable to create AudioClip from input stream"); - } } @Override public synchronized void play() { startImpl(false); } @Override public synchronized void loop() { startImpl(true); } private synchronized void startImpl(boolean loop) { // hack for some applets that call the start method very rapidly... --- 140,164 ---- success = createSequencer(bis); } catch (InvalidMidiDataException e1) { success = false; } } } @Override public synchronized void play() { + if (!success) { + return; + } startImpl(false); } @Override public synchronized void loop() { + if (!success) { + return; + } startImpl(true); } private synchronized void startImpl(boolean loop) { // hack for some applets that call the start method very rapidly...
*** 204,213 **** --- 229,241 ---- } } @Override public synchronized void stop() { + if (!success) { + return; + } if (DEBUG || Printer.debug)Printer.debug("JavaSoundAudioClip->stop()"); lastPlayCall = 0; if (clip != null) {
< prev index next >