@@ -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