1.1 --- a/sound/src/main/java/net/java/html/sound/AudioClip.java Sat Aug 17 14:31:06 2013 +0200
1.2 +++ b/sound/src/main/java/net/java/html/sound/AudioClip.java Wed Aug 21 17:38:59 2013 +0200
1.3 @@ -34,6 +34,9 @@
1.4 }
1.5
1.6 /** Creates new instance of an audio clip based on the provided URL.
1.7 + * If no suitable audio environment provider is found, the method
1.8 + * returns a dummy instance that does nothing and only returns
1.9 + * false from its {@link #isSupported()} method.
1.10 *
1.11 * @param src the URL where to find the audio clip
1.12 * @return the audio clip handle
1.13 @@ -47,7 +50,7 @@
1.14 return handle;
1.15 }
1.16 }
1.17 - throw new IllegalStateException();
1.18 + return DummyClip.INSTANCE;
1.19 }
1.20
1.21 /** Plays the clip from begining to the end.
1.22 @@ -69,6 +72,12 @@
1.23 * @param volume for the playback
1.24 */
1.25 public abstract void setVolume(double volume);
1.26 +
1.27 + /** Check whether the audio clip is supported and can be played.
1.28 + * @return true if it is likely that after calling {@link #play()}
1.29 + * a sound will be produced
1.30 + */
1.31 + public abstract boolean isSupported();
1.32
1.33 // public abstract void playFrom(int seconds);
1.34
1.35 @@ -112,6 +121,11 @@
1.36 }
1.37
1.38 @Override
1.39 + public boolean isSupported() {
1.40 + return env.isSupported(clip);
1.41 + }
1.42 +
1.43 + @Override
1.44 public int hashCode() {
1.45 return 59 * src.hashCode();
1.46 }
1.47 @@ -124,4 +138,25 @@
1.48 return false;
1.49 }
1.50 } // end of Impl
1.51 +
1.52 + private static final class DummyClip extends AudioClip {
1.53 + static AudioClip INSTANCE = new DummyClip();
1.54 +
1.55 + @Override
1.56 + public void play() {
1.57 + }
1.58 +
1.59 + @Override
1.60 + public void pause() {
1.61 + }
1.62 +
1.63 + @Override
1.64 + public void setVolume(double volume) {
1.65 + }
1.66 +
1.67 + @Override
1.68 + public boolean isSupported() {
1.69 + return false;
1.70 + }
1.71 + } // end of DummyClip
1.72 }
1.73 \ No newline at end of file
2.1 --- a/sound/src/main/java/org/apidesign/html/sound/spi/AudioEnvironment.java Sat Aug 17 14:31:06 2013 +0200
2.2 +++ b/sound/src/main/java/org/apidesign/html/sound/spi/AudioEnvironment.java Wed Aug 21 17:38:59 2013 +0200
2.3 @@ -33,4 +33,6 @@
2.4 public void pause(Audio a);
2.5
2.6 public void setVolume(Audio a, double volume);
2.7 +
2.8 + public boolean isSupported(Audio a);
2.9 }