# HG changeset patch # User Jaroslav Tulach # Date 1375882182 -7200 # Node ID ef2399c0fb9eb352bd55d97850b9864a016402a0 # Parent 63b36aba87c7f038ab226968a9237e764736c5a2 Implementation of the AudioClip that uses HTML5 Audio tag diff -r 63b36aba87c7 -r ef2399c0fb9e sound/pom.xml --- a/sound/pom.xml Wed Aug 07 14:28:21 2013 +0200 +++ b/sound/pom.xml Wed Aug 07 15:29:42 2013 +0200 @@ -5,12 +5,12 @@ org.apidesign html - 0.4-SNAPSHOT + 0.5-SNAPSHOT - net.java.html - sound - 1.0-SNAPSHOT - Sound API for Java + org.apidesign.html + net.java.html.sound + 0.5-SNAPSHOT + Sound API via HTML http://maven.apache.org UTF-8 @@ -22,6 +22,7 @@ maven-javadoc-plugin false + net.java.html.sound @@ -30,8 +31,18 @@ org.testng testng - 6.5.2 test + + org.apidesign.html + net.java.html.boot + 0.5-SNAPSHOT + jar + + + org.netbeans.api + org-openide-util-lookup + provided + diff -r 63b36aba87c7 -r ef2399c0fb9e sound/src/main/java/net/java/html/sound/AudioClip.java --- a/sound/src/main/java/net/java/html/sound/AudioClip.java Wed Aug 07 14:28:21 2013 +0200 +++ b/sound/src/main/java/net/java/html/sound/AudioClip.java Wed Aug 07 15:29:42 2013 +0200 @@ -1,106 +1,127 @@ /** - * Back 2 Browser Bytecode Translator Copyright (C) 2012 Jaroslav Tulach - * + * HTML via Java(tm) Language Bindings + * Copyright (C) 2013 Jaroslav Tulach * - * This program is free software: you can redistribute it and/or modify it under - * the terms of the GNU General Public License as published by the Free Software - * Foundation, version 2 of the License. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 2 of the License. * - * This program 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 for more - * details. + * This program 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 for more details. apidesign.org + * designates this particular file as subject to the + * "Classpath" exception as provided by apidesign.org + * in the License file that accompanied this code. * - * You should have received a copy of the GNU General Public License along with - * this program. Look for COPYING file in the top folder. If not, see - * http://opensource.org/licenses/GPL-2.0. + * You should have received a copy of the GNU General Public License + * along with this program. Look for COPYING file in the top folder. + * If not, see http://wiki.apidesign.org/wiki/GPLwithClassPathException */ package net.java.html.sound; import java.util.ServiceLoader; import org.apidesign.html.sound.spi.AudioEnvironment; -/** +/** Handle to an audio clip which can be {@link #play() played}, {@link #pause() paused} + * and etc. Obtain new instance via {@link #create(java.lang.String) create} factory + * method and then use it when necessary. * * @author antonepple */ -public final class AudioClip { - - private Object cached; - private int cacheHash; - private final String src; - private final AudioEnvironment audioEnvironment; - - private AudioClip(String src) { - this.src = src; - ServiceLoader loader = ServiceLoader.load(AudioEnvironment.class); - audioEnvironment = loader.iterator().next(); +public abstract class AudioClip { + private AudioClip() { } + /** Creates new instance of an audio clip based on the provided URL. + * + * @param src the URL where to find the audio clip + * @return the audio clip handle + * @throws NullPointerException if src is null + */ public static AudioClip create(String src) { - return new AudioClip(src); + src.getClass(); + for (AudioEnvironment ae : ServiceLoader.load(AudioEnvironment.class)) { + Impl handle = create(ae, src); + if (handle != null) { + return handle; + } + } + throw new IllegalStateException(); } + + /** Plays the clip from begining to the end. + */ + public abstract void play(); - public void play() { - Object nativeClip = audioEnvironment.play(this, cached); - cache(nativeClip); + /** Pauses playback of the clip + */ + public abstract void pause(); + + /** + * Specifies the volume of the audio. Must be a number between 0.0 and 1.0: + *
    + *
  • 1.0 - highest volume
  • + *
  • 0.5 - 50% volume
  • + *
  • 0.0 - silent
  • + *
+ * + * @param volume for the playback + */ + public abstract void setVolume(double volume); + +// public abstract void playFrom(int seconds); + + // + // Implementation + // + + private static