1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.htmlunit.javascript.host.media;
16
17 import org.htmlunit.corejs.javascript.Function;
18 import org.htmlunit.corejs.javascript.NativePromise;
19 import org.htmlunit.corejs.javascript.typedarrays.NativeArrayBuffer;
20 import org.htmlunit.html.HtmlPage;
21 import org.htmlunit.javascript.JavaScriptEngine;
22 import org.htmlunit.javascript.PostponedAction;
23 import org.htmlunit.javascript.configuration.JsxClass;
24 import org.htmlunit.javascript.configuration.JsxConstructor;
25 import org.htmlunit.javascript.configuration.JsxFunction;
26 import org.htmlunit.javascript.host.Window;
27 import org.htmlunit.javascript.host.dom.DOMException;
28 import org.htmlunit.javascript.host.event.EventTarget;
29
30
31
32
33
34
35
36 @JsxClass
37 public class BaseAudioContext extends EventTarget {
38
39
40
41
42 @Override
43 @JsxConstructor
44 public void jsConstructor() {
45 throw JavaScriptEngine.typeErrorIllegalConstructor();
46 }
47
48
49
50
51
52 @JsxFunction
53 public AudioBufferSourceNode createBufferSource() {
54 final AudioBufferSourceNode node = new AudioBufferSourceNode();
55 node.setParentScope(getParentScope());
56 node.setPrototype(getPrototype(node.getClass()));
57 return node;
58 }
59
60
61
62
63
64 @JsxFunction
65 public AudioBuffer createBuffer() {
66 final AudioBuffer node = new AudioBuffer();
67 node.setParentScope(getParentScope());
68 node.setPrototype(getPrototype(node.getClass()));
69 return node;
70 }
71
72
73
74
75 @JsxFunction
76 public GainNode createGain() {
77 final GainNode node = new GainNode();
78 node.setParentScope(getParentScope());
79 node.setPrototype(getPrototype(node.getClass()));
80 node.jsConstructor(this);
81 return node;
82 }
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100 @JsxFunction
101 public NativePromise decodeAudioData(final NativeArrayBuffer buffer, final Function success, final Function error) {
102 final Window window = getWindow();
103 final HtmlPage owningPage = (HtmlPage) window.getDocument().getPage();
104 final JavaScriptEngine jsEngine =
105 (JavaScriptEngine) window.getWebWindow().getWebClient().getJavaScriptEngine();
106
107 final DOMException domException = new DOMException(
108 "decodeAudioData not supported by HtmlUnit", DOMException.NOT_SUPPORTED_ERR);
109 domException.setParentScope(window);
110 domException.setPrototype(window.getPrototype(DOMException.class));
111
112 if (error != null) {
113 jsEngine.addPostponedAction(new PostponedAction(owningPage, "BaseAudioContext.decodeAudioData") {
114 @Override
115 public void execute() {
116 jsEngine.callFunction(owningPage, error, getParentScope(), BaseAudioContext.this,
117 new Object[] {domException});
118 }
119 });
120 return null;
121 }
122
123 return setupRejectedPromise(() -> domException);
124 }
125 }