toni@1161
|
1 |
/*
|
toni@1161
|
2 |
* To change this template, choose Tools | Templates
|
toni@1161
|
3 |
* and open the template in the editor.
|
toni@1161
|
4 |
*/
|
toni@1161
|
5 |
package org.apidesign.bck2brwsr.htmlpage;
|
toni@1161
|
6 |
|
toni@1161
|
7 |
import net.java.html.sound.AudioClip;
|
toni@1161
|
8 |
import org.apidesign.bck2brwsr.core.JavaScriptBody;
|
toni@1161
|
9 |
import org.apidesign.html.sound.spi.AudioEnvironment;
|
toni@1163
|
10 |
import org.openide.util.lookup.ServiceProvider;
|
toni@1161
|
11 |
|
toni@1163
|
12 |
@ServiceProvider(service = AudioEnvironment.class)
|
toni@1161
|
13 |
public class HTML5AudioEnvironment implements AudioEnvironment {
|
toni@1161
|
14 |
|
toni@1161
|
15 |
@Override
|
toni@1161
|
16 |
public Object play(AudioClip clip, Object nativeClip) {
|
toni@1161
|
17 |
if (nativeClip == null) {
|
toni@1161
|
18 |
nativeClip = createNativeCLip(clip.getSource());
|
toni@1161
|
19 |
}
|
toni@1161
|
20 |
playImpl(nativeClip);
|
toni@1161
|
21 |
return nativeClip;
|
toni@1161
|
22 |
}
|
toni@1161
|
23 |
|
toni@1161
|
24 |
@Override
|
toni@1161
|
25 |
public Object pause(AudioClip aThis, Object nativeClip) {
|
toni@1161
|
26 |
if (nativeClip == null) {
|
toni@1161
|
27 |
return null; // only can pause a cached clip
|
toni@1161
|
28 |
}
|
toni@1161
|
29 |
pauseImpl(nativeClip);
|
toni@1161
|
30 |
return nativeClip;
|
toni@1161
|
31 |
}
|
toni@1161
|
32 |
|
toni@1161
|
33 |
@Override
|
toni@1161
|
34 |
public Object stop(AudioClip aThis, Object nativeClip) {
|
toni@1161
|
35 |
if (nativeClip == null) {
|
toni@1161
|
36 |
return null; // only can stop a cached clip
|
toni@1161
|
37 |
}
|
toni@1161
|
38 |
stopImpl(nativeClip);
|
toni@1161
|
39 |
return nativeClip;
|
toni@1161
|
40 |
}
|
toni@1161
|
41 |
|
toni@1161
|
42 |
@Override
|
toni@1161
|
43 |
public Object setVolume(AudioClip aThis, int volume, Object cached) {
|
toni@1161
|
44 |
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
toni@1161
|
45 |
}
|
toni@1161
|
46 |
|
toni@1161
|
47 |
@Override
|
toni@1161
|
48 |
public Object playFrom(AudioClip clip, int seconds, Object nativeClip) {
|
toni@1161
|
49 |
if (nativeClip == null) {
|
toni@1161
|
50 |
nativeClip = createNativeCLip(clip.getSource());
|
toni@1161
|
51 |
}
|
toni@1161
|
52 |
playFromImpl(nativeClip);
|
toni@1161
|
53 |
return nativeClip;
|
toni@1161
|
54 |
}
|
toni@1161
|
55 |
|
toni@1161
|
56 |
@JavaScriptBody(args = "nativeClip", body = "nativeClip.play()")
|
toni@1161
|
57 |
private native void playImpl(Object nativeClip);
|
toni@1161
|
58 |
|
toni@1161
|
59 |
@JavaScriptBody(args = "nativeClip", body = "nativeClip.pause(), nativeClip.currentTime=0;")
|
toni@1161
|
60 |
private void stopImpl(Object nativeClip) {
|
toni@1161
|
61 |
}
|
toni@1161
|
62 |
|
toni@1161
|
63 |
@JavaScriptBody(args = "nativeClip", body = "nativeClip.pause();")
|
toni@1161
|
64 |
private void pauseImpl(Object nativeClip) {
|
toni@1161
|
65 |
}
|
toni@1161
|
66 |
|
toni@1161
|
67 |
@JavaScriptBody(args = "nativeClip", body = "nativeClip.currentTime=0; nativeClip.play();")
|
toni@1161
|
68 |
private void playFromImpl(Object nativeClip) {
|
toni@1161
|
69 |
}
|
toni@1161
|
70 |
|
toni@1161
|
71 |
@JavaScriptBody(args = {"src"}, body = "var clip = new Audio();clip.src=src; return clip;")
|
toni@1161
|
72 |
private native Object createNativeCLip(String src);
|
toni@1161
|
73 |
}
|