Advertisement
BrU32

Web Audio API Vol Adjust Based On Cursor X Pos

May 29th, 2016
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. <audio controls autoplay src="http://mdn.github.io/media-source-buffer/viper.ogg" type="audio/ogg" controls autoplay>
  2. </audio>
  3. <pre>
  4. <script>
  5. var audioCtx = new (window.AudioContext || window.webkitAudioContext)();
  6. var myAudio = document.querySelector('audio');
  7. var pre = document.querySelector('pre');
  8. var myScript = document.querySelector('script');
  9. pre.innerHTML = document.body.innerText;
  10. var osc=audioCtx.createOscillator();
  11. var source = audioCtx.createMediaElementSource(myAudio);
  12. var gainNode = audioCtx.createGain(source);
  13. var CurX;
  14. var WIDTH = window.innerHeight;
  15. document.onmousemove = updatePage;
  16. function updatePage(e) {
  17. CurX = (window.Event) ? e.pageX : event.clientX + (document.documentElement.scrolLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
  18. gainNode.gain.value = CurX/WIDTH;
  19. myAudio.volume = CurX/WIDTH;
  20. }
  21. source.connect(gainNode);
  22. gainNode.connect(audioCtx.destination);
  23. </script>
  24. </pre>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement