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@1161
|
10 |
|
toni@1161
|
11 |
/**
|
toni@1161
|
12 |
*
|
toni@1161
|
13 |
* @author antonepple
|
toni@1161
|
14 |
*/
|
toni@1161
|
15 |
public class HTML5AudioEnvironment implements AudioEnvironment {
|
toni@1161
|
16 |
|
toni@1161
|
17 |
@Override
|
toni@1161
|
18 |
public Object play(AudioClip clip, Object nativeClip) {
|
toni@1161
|
19 |
if (nativeClip == null) {
|
toni@1161
|
20 |
nativeClip = createNativeCLip(clip.getSource());
|
toni@1161
|
21 |
}
|
toni@1161
|
22 |
playImpl(nativeClip);
|
toni@1161
|
23 |
return nativeClip;
|
toni@1161
|
24 |
}
|
toni@1161
|
25 |
|
toni@1161
|
26 |
@Override
|
toni@1161
|
27 |
public Object pause(AudioClip aThis, Object nativeClip) {
|
toni@1161
|
28 |
if (nativeClip == null) {
|
toni@1161
|
29 |
return null; // only can pause a cached clip
|
toni@1161
|
30 |
}
|
toni@1161
|
31 |
pauseImpl(nativeClip);
|
toni@1161
|
32 |
return nativeClip;
|
toni@1161
|
33 |
}
|
toni@1161
|
34 |
|
toni@1161
|
35 |
@Override
|
toni@1161
|
36 |
public Object stop(AudioClip aThis, Object nativeClip) {
|
toni@1161
|
37 |
if (nativeClip == null) {
|
toni@1161
|
38 |
return null; // only can stop a cached clip
|
toni@1161
|
39 |
}
|
toni@1161
|
40 |
stopImpl(nativeClip);
|
toni@1161
|
41 |
return nativeClip;
|
toni@1161
|
42 |
}
|
toni@1161
|
43 |
|
toni@1161
|
44 |
@Override
|
toni@1161
|
45 |
public Object setVolume(AudioClip aThis, int volume, Object cached) {
|
toni@1161
|
46 |
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
toni@1161
|
47 |
}
|
toni@1161
|
48 |
|
toni@1161
|
49 |
@Override
|
toni@1161
|
50 |
public Object playFrom(AudioClip clip, int seconds, Object nativeClip) {
|
toni@1161
|
51 |
if (nativeClip == null) {
|
toni@1161
|
52 |
nativeClip = createNativeCLip(clip.getSource());
|
toni@1161
|
53 |
}
|
toni@1161
|
54 |
playFromImpl(nativeClip);
|
toni@1161
|
55 |
return nativeClip;
|
toni@1161
|
56 |
}
|
toni@1161
|
57 |
|
toni@1161
|
58 |
@JavaScriptBody(args = "nativeClip", body = "nativeClip.play()")
|
toni@1161
|
59 |
private native void playImpl(Object nativeClip);
|
toni@1161
|
60 |
|
toni@1161
|
61 |
@JavaScriptBody(args = "nativeClip", body = "nativeClip.pause(), nativeClip.currentTime=0;")
|
toni@1161
|
62 |
private void stopImpl(Object nativeClip) {
|
toni@1161
|
63 |
}
|
toni@1161
|
64 |
|
toni@1161
|
65 |
@JavaScriptBody(args = "nativeClip", body = "nativeClip.pause();")
|
toni@1161
|
66 |
private void pauseImpl(Object nativeClip) {
|
toni@1161
|
67 |
}
|
toni@1161
|
68 |
|
toni@1161
|
69 |
@JavaScriptBody(args = "nativeClip", body = "nativeClip.currentTime=0; nativeClip.play();")
|
toni@1161
|
70 |
private void playFromImpl(Object nativeClip) {
|
toni@1161
|
71 |
}
|
toni@1161
|
72 |
|
toni@1161
|
73 |
@JavaScriptBody(args = {"src"}, body = "var clip = new Audio();clip.src=src; return clip;")
|
toni@1161
|
74 |
private native Object createNativeCLip(String src);
|
toni@1161
|
75 |
}
|