mostly filebased Content Presentation System
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

freaWebAudio.js 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. function AudioTagSample() {
  2. // initialize audio player
  3. this.audio = new Audio();
  4. this.isPlaying = false;
  5. window.addEventListener('load', this.onload.bind(this), false);
  6. }
  7. AudioTagSample.prototype.onload = function() {
  8. // Create the audio nodes.
  9. this.source = context.createMediaElementSource(this.audio);
  10. this.source.connect(context.destination);
  11. };
  12. AudioTagSample.prototype.click = function(link) {
  13. var was_inactive = this.audio.paused
  14. var was_the_same = this.audio.src == link.href
  15. var controls = document.querySelectorAll('.controls');
  16. for (i=0;i<controls.length;i++){
  17. controls[i].classList.toggle("playing");
  18. controls[i].classList.remove("fresh");
  19. };
  20. if (was_the_same) {
  21. if (this.audio.paused) {
  22. this.audio.play();
  23. link.classList.remove("paused")
  24. link.classList.add("playing")
  25. } else {
  26. this.audio.pause();
  27. link.classList.remove("playing")
  28. link.classList.add("paused")
  29. }
  30. } else {
  31. if(this.link) {
  32. this.link.classList.remove("playing")
  33. this.link.classList.remove("paused")
  34. }
  35. this.audio.src = link.href;
  36. this.link = link
  37. this.audio.play();
  38. link.classList.remove("paused")
  39. link.classList.add("playing")
  40. }
  41. if (was_inactive) {
  42. requestAnimFrame(this.draw.bind(this));
  43. }
  44. this.link = link;
  45. };