Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2014
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.13 KB | None | 0 0
  1. $(window).load(function () {
  2. var i = 0;
  3.  
  4. var PVstartButtons = document.getElementsByClassName('start-button', i);
  5. var PVaudioSources = [];
  6. var PVstartTimes = [];
  7. var PVendTimes = [];
  8.  
  9. var playerWrapper = document.getElementById('player-wrapper');
  10.  
  11. for (i = 0; i < PVstartButtons.length; ++i) {
  12. PVstartButtons[i].addEventListener("click", PVplayMedia(i));
  13. PVaudioSources[i] = PVstartButtons[i].getAttribute('audioSource');
  14. PVstartTimes[i] = PVstartButtons[i].getAttribute('timeBegins');
  15. PVendTimes[i] = PVstartButtons[i].getAttribute('timeEnds');
  16. }
  17.  
  18. window.playerWrapper = playerWrapper;
  19. window.PVstartButtons = PVstartButtons;
  20. window.PVaudioSources = PVaudioSources;
  21. window.PVstartTimes = PVstartTimes;
  22. window.PVendTimes = PVendTimes;
  23.  
  24. });
  25.  
  26. function PVplayMedia(i) {
  27. return function () {
  28. if (playerWrapper.hasAttribute("haschild") === true) {
  29. var child = playerWrapper.children[0];
  30. $(child).remove();
  31. } else {
  32. playerWrapper.setAttribute("haschild", "true");
  33. }
  34. var audio = document.createElement('audio');
  35. audio.setAttribute('controls', '');
  36. audio.setAttribute('preload', 'none');
  37. playerWrapper.appendChild(audio);
  38.  
  39. var source = document.createElement('source');
  40. source.setAttribute('src', PVaudioSources[i]);
  41. audio.appendChild(source);
  42.  
  43. audio.load();
  44. audio.onloadedmetadata = function() {
  45. audio.currentTime = PVstartTimes[i];
  46. audio.play();
  47. };
  48. audio.addEventListener('timeupdate', function() {
  49. if (PVendTimes[i] && audio.currentTime >= PVendTimes[i]) {
  50. audio.pause();
  51. audio.currentTime = PVstartTimes[i];
  52. }
  53. },false);
  54.  
  55. }
  56. }
  57.  
  58. <!DOCTYPE html>
  59. <html>
  60.  
  61. <head>
  62. <link rel="stylesheet" href="style.css">
  63. <script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
  64. <script src="script.js"></script>
  65. </head>
  66.  
  67. <body>
  68.  
  69. <div id="player-wrapper">
  70. </div>
  71. <br>
  72. <button class="btn btn-primary start-button"
  73. audioSource="http://media.blubrry.com/burr/traffic.libsyn.com/billburr/MMPC_7-21-14.mp3"
  74. timeBegins="105"
  75. timeEnds="110">
  76. Start MMP - mp3 - 1:45 to 1:50
  77. </button>
  78. <br>
  79. <button class="btn btn-primary start-button"
  80. audioSource="http://media.blubrry.com/burr/traffic.libsyn.com/billburr/MMPC_7-21-14.mp3"
  81. timeBegins="3600"
  82. timeEnds="3605">
  83. Start MMP - mp3 - 1:00:00 to 1:00:05
  84. </button>
  85. <br>
  86. <button class="btn btn-primary start-button"
  87. audioSource="http://media.blubrry.com/burr/traffic.libsyn.com/billburr/MMPC_7-21-14.mp3"
  88. timeBegins="1800"
  89. timeEnds="1805">
  90. Start MMP - mp3 - 30:00 to 30:05
  91. </button>
  92. <br><br>
  93. <button class="btn btn-primary start-button"
  94. audioSource="http://traffic.libsyn.com/joeroganexp/p523.mp3"
  95. timeBegins="100"
  96. timeEnds="105">
  97. Start JRE #523 - mp3 - 1:40 to 1:45
  98. </button>
  99. <br>
  100. <button class="btn btn-primary start-button"
  101. audioSource="http://traffic.libsyn.com/joeroganexp/p523.mp3"
  102. timeBegins="3600"
  103. timeEnds="3605">
  104. Start JRE #523 - mp3 - 1:00:00 to 1:00:05
  105. </button>
  106. <br>
  107. <button class="btn btn-primary start-button"
  108. audioSource="http://traffic.libsyn.com/joeroganexp/p523.mp3"
  109. timeBegins="1800"
  110. timeEnds="1805">
  111. Start JRE #523 - mp3 - 30:00 to 30:05
  112. </button>
  113. <br><br>
  114. <button class="btn btn-primary start-button"
  115. audioSource="http://www.tuxradar.com/files/podcast/tuxradar_s06e02.ogg"
  116. timeBegins="200"
  117. timeEnds="205">
  118. TuxRadar Linux Podcast - ogg - 3:20 to 3:25
  119. </button>
  120. <br>
  121. <button class="btn btn-primary start-button"
  122. audioSource="http://www.tuxradar.com/files/podcast/tuxradar_s06e02.ogg"
  123. timeBegins="1000"
  124. timeEnds="1005">
  125. TuxRadar Linux Podcast - ogg - 16:40 to 16:45
  126. </button>
  127. <br>
  128. <button class="btn btn-primary start-button"
  129. audioSource="http://www.tuxradar.com/files/podcast/tuxradar_s06e02.ogg"
  130. timeBegins="1500"
  131. timeEnds="1505">
  132. TuxRadar Linux Podcast - ogg - 25:00 to 25:05
  133. </button>
  134.  
  135. <br><br>
  136. <button class="btn btn-primary start-button"
  137. audioSource="http://www.linuxvoice.com/episodes/lv_s02e13.ogg"
  138. timeBegins="200"
  139. timeEnds="205">
  140. Linux Voice - ogg - 3:20 to 3:25
  141. </button>
  142. <br>
  143. <button class="btn btn-primary start-button"
  144. audioSource="http://www.linuxvoice.com/episodes/lv_s02e13.ogg"
  145. timeBegins="3600"
  146. timeEnds="3605">
  147. Linux Voice - ogg - 1:00:00 to 1:00:05
  148. </button>
  149. <br>
  150. <button class="btn btn-primary start-button"
  151. audioSource="http://www.linuxvoice.com/episodes/lv_s02e13.ogg"
  152. timeBegins="1000"
  153. timeEnds="1005">
  154. Linux Voice - ogg - 16:40 to 16:45
  155. </button>
  156.  
  157.  
  158. </body>
  159.  
  160. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement