Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  6. <meta name="viewport" content="width=device-width">
  7.  
  8. <title>StereoPannerNode example</title>
  9.  
  10. <link rel="stylesheet" href="">
  11. <!--[if lt IE 9]>
  12. <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
  13. <![endif]-->
  14. </head>
  15.  
  16. <body>
  17. <h1>StereoPannerNode example</h1>
  18. <audio controls>
  19. <source src="omg.mp3" type="audio/mp3">
  20. <p>Browser too old to support HTML5 audio? How depressing!</p>
  21. </audio>
  22. <h2>Set stereo panning</h2>
  23. <input class="panning-control" type="range" min="-1" max="1" step="0.1" value="0">
  24. <span class="panning-value">0</span>
  25.  
  26. </body>
  27. <script>
  28. var audioCtx = new (window.AudioContext || window.webkitAudioContext)();
  29. var myAudio = document.querySelector('audio');
  30.  
  31. var panControl = document.querySelector('.panning-control');
  32. var panValue = document.querySelector('.panning-value');
  33.  
  34.  
  35. // Create a MediaElementAudioSourceNode
  36. // Feed the HTMLMediaElement into it
  37. var source = audioCtx.createMediaElementSource(myAudio);
  38.  
  39. // Create a stereo panner
  40. var panNode = audioCtx.createStereoPanner();
  41.  
  42. // Event handler function to increase panning to the right and left
  43. // when the slider is moved
  44.  
  45. panControl.oninput = function() {
  46. panNode.pan.value = panControl.value;
  47. panValue.innerHTML = panControl.value;
  48. }
  49.  
  50. // connect the AudioBufferSourceNode to the gainNode
  51. // and the gainNode to the destination, so we can play the
  52. // music and adjust the panning using the controls
  53. source.connect(panNode);
  54. panNode.connect(audioCtx.destination);
  55. </script>
  56. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement