Web Audio API | AudioNode context property

The AudioNode interface has a context property which returns the related BaseAudioContext, which is the object that represents the process graph the node that has participated.

Syntax:

var ctx = anAudioNode.context;

Return Value: It returns a AudioContext or OfflineAudioContext object.

Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<head>
    <title>
        AudioNode context property
    </title>
</head>
  
<body>
  
    <h1 style="color:green">
        GeeksforGeeks
    </h1>
      
    <h2>AudioNode context property</h2>
      
    <script>
        const AudioContext =
            window.AudioContext || window.webkitAudioContext;
  
        const audioCnt = new AudioContext();
  
        // Oscillator
        const osciltr = audioCnt.createOscillator();
  
        // Gain node
        const GainNode = audioCnt.createGain();
        osciltr.connect(GainNode).connect(audioCnt.destination);
  
        console.log(osciltr.context);
    </script>
</body>
  
</html>

chevron_right


Output:

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<head>
    <title>
        AudioNode context property
    </title>
</head>
  
<body>
    <h1 style="color:green">
        GeeksforGeeks
    </h1>
      
    <h2>AudioNode context property</h2>
      
    <script>
        const AudioContext =
            window.AudioContext || window.webkitAudioContext;
          
        const audioCnt = new AudioContext();
  
        // Oscillator
        const osciltr = audioCnt.createOscillator();
  
        // Gain_node
        const gNode = audioCnt.createGain();
        osciltr.connect(gNode).connect(audioCnt.destination);
  
        console.log(osciltr.context === audioCnt);
    </script>
</body>
  
</html>

chevron_right


Output:

Supported Browsers: The browsers supported by AudioNode context property are listed below:

  • Google Chrome 35.0
  • Firefox 25.0
  • Apple Safari 6 -x-
  • Opera 22.0


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.