sound/src/main/java/org/apidesign/html/sound/impl/BrowserAudioEnv.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Wed, 07 Aug 2013 15:29:42 +0200
branchsound
changeset 223 ef2399c0fb9e
child 249 18430f810b7e
permissions -rw-r--r--
Implementation of the AudioClip that uses HTML5 Audio tag
     1 /**
     2  * HTML via Java(tm) Language Bindings
     3  * Copyright (C) 2013 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
     4  *
     5  * This program is free software: you can redistribute it and/or modify
     6  * it under the terms of the GNU General Public License as published by
     7  * the Free Software Foundation, version 2 of the License.
     8  *
     9  * This program is distributed in the hope that it will be useful,
    10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    12  * GNU General Public License for more details. apidesign.org
    13  * designates this particular file as subject to the
    14  * "Classpath" exception as provided by apidesign.org
    15  * in the License file that accompanied this code.
    16  *
    17  * You should have received a copy of the GNU General Public License
    18  * along with this program. Look for COPYING file in the top folder.
    19  * If not, see http://wiki.apidesign.org/wiki/GPLwithClassPathException
    20  */
    21 package org.apidesign.html.sound.impl;
    22 
    23 import net.java.html.js.JavaScriptBody;
    24 import org.apidesign.html.sound.spi.AudioEnvironment;
    25 import org.openide.util.lookup.ServiceProvider;
    26 
    27 /** Registers an audio provider that delegates to HTML5 Audio tag.
    28  *
    29  * @author Jaroslav Tulach <jtulach@netbeans.org>
    30  */
    31 @ServiceProvider(service = AudioEnvironment.class, position = 100)
    32 public final class BrowserAudioEnv implements AudioEnvironment<Object> {
    33     @Override
    34     @JavaScriptBody(args = { "src" }, body = ""
    35         + "if (!Audio) return null;"
    36         + "return new Audio(src);")
    37     public Object create(String src) {
    38         // null if not running in browser
    39         return null;
    40     }
    41 
    42     @Override @JavaScriptBody(args = { "a" }, body = "a.play();")
    43     public void play(Object a) {
    44     }
    45 
    46     @Override @JavaScriptBody(args = { "a" }, body = "a.pause();")
    47     public void pause(Object a) {
    48     }
    49 
    50     @Override @JavaScriptBody(args = { "a", "volume" }, body = "a.setVolume(volume);")
    51     public void setVolume(Object a, double volume) {
    52     }
    53 }