Skip to content

Commit 65a8008

Browse files
authored
Merge pull request #8176 from processing/fix/connect
Fix usage of fn in MediaElement.connect
2 parents a527f88 + 6bff531 commit 65a8008

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

src/dom/p5.MediaElement.js

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -935,6 +935,13 @@ class MediaElement extends Element {
935935

936936
/*** CONNECT TO WEB AUDIO API / p5.sound.js ***/
937937

938+
_getAudioContext() {
939+
return undefined;
940+
}
941+
_getSoundOut() {
942+
return undefined;
943+
}
944+
938945
/**
939946
* Sends the element's audio to an output.
940947
*
@@ -954,9 +961,9 @@ class MediaElement extends Element {
954961
let audioContext, mainOutput;
955962

956963
// if p5.sound exists, same audio context
957-
if (typeof fn.getAudioContext === 'function') {
958-
audioContext = fn.getAudioContext();
959-
mainOutput = p5.soundOut.input;
964+
if (this._getAudioContext() && this._getSoundOut()) {
965+
audioContext = this._getAudioContext();
966+
mainOutput = this._getSoundOut().input;
960967
} else {
961968
try {
962969
audioContext = obj.context;
@@ -1792,6 +1799,19 @@ function media(p5, fn){
17921799
*/
17931800
p5.MediaElement = MediaElement;
17941801

1802+
// Patch MediaElement to give it access to fn, which p5.sound may attach things to
1803+
// if present in a sketch
1804+
MediaElement.prototype._getSoundOut = function() {
1805+
return p5.soundOut;
1806+
}
1807+
MediaElement.prototype._getAudioContext = function() {
1808+
if (typeof fn.getAudioContext === 'function') {
1809+
return fn.getAudioContext();
1810+
} else {
1811+
return undefined;
1812+
}
1813+
}
1814+
17951815
/**
17961816
* Path to the media element's source as a string.
17971817
*

0 commit comments

Comments
 (0)