Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions src/dom/p5.MediaElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -935,6 +935,13 @@ class MediaElement extends Element {

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

_getAudioContext() {
return undefined;
}
_getSoundOut() {
return undefined;
}

/**
* Sends the element's audio to an output.
*
Expand All @@ -954,9 +961,9 @@ class MediaElement extends Element {
let audioContext, mainOutput;

// if p5.sound exists, same audio context
if (typeof fn.getAudioContext === 'function') {
audioContext = fn.getAudioContext();
mainOutput = p5.soundOut.input;
if (this._getAudioContext() && this._getSoundOut()) {
audioContext = this._getAudioContext();
mainOutput = this._getSoundOut().input;
} else {
try {
audioContext = obj.context;
Expand Down Expand Up @@ -1792,6 +1799,19 @@ function media(p5, fn){
*/
p5.MediaElement = MediaElement;

// Patch MediaElement to give it access to fn, which p5.sound may attach things to
// if present in a sketch
MediaElement.prototype._getSoundOut = function() {
return p5.soundOut;
}
MediaElement.prototype._getAudioContext = function() {
if (typeof fn.getAudioContext === 'function') {
return fn.getAudioContext();
} else {
return undefined;
}
}

/**
* Path to the media element's source as a string.
*
Expand Down
Loading