Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $(window).load(function () {
- var i = 0;
- var PVstartButtons = document.getElementsByClassName('start-button', i);
- var PVaudioSources = [];
- var PVstartTimes = [];
- var PVendTimes = [];
- var playerWrapper = document.getElementById('player-wrapper');
- for (i = 0; i < PVstartButtons.length; ++i) {
- PVstartButtons[i].addEventListener("click", PVplayMedia(i));
- PVaudioSources[i] = PVstartButtons[i].getAttribute('audioSource');
- PVstartTimes[i] = PVstartButtons[i].getAttribute('timeBegins');
- PVendTimes[i] = PVstartButtons[i].getAttribute('timeEnds');
- }
- window.playerWrapper = playerWrapper;
- window.PVstartButtons = PVstartButtons;
- window.PVaudioSources = PVaudioSources;
- window.PVstartTimes = PVstartTimes;
- window.PVendTimes = PVendTimes;
- });
- function PVplayMedia(i) {
- return function () {
- if (playerWrapper.hasAttribute("haschild") === true) {
- var child = playerWrapper.children[0];
- $(child).remove();
- } else {
- playerWrapper.setAttribute("haschild", "true");
- }
- var audio = document.createElement('audio');
- audio.setAttribute('controls', '');
- audio.setAttribute('preload', 'none');
- playerWrapper.appendChild(audio);
- var source = document.createElement('source');
- source.setAttribute('src', PVaudioSources[i]);
- audio.appendChild(source);
- audio.load();
- audio.onloadedmetadata = function() {
- audio.currentTime = PVstartTimes[i];
- audio.play();
- };
- audio.addEventListener('timeupdate', function() {
- if (PVendTimes[i] && audio.currentTime >= PVendTimes[i]) {
- audio.pause();
- audio.currentTime = PVstartTimes[i];
- }
- },false);
- }
- }
- <!DOCTYPE html>
- <html>
- <head>
- <link rel="stylesheet" href="style.css">
- <script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
- <script src="script.js"></script>
- </head>
- <body>
- <div id="player-wrapper">
- </div>
- <br>
- <button class="btn btn-primary start-button"
- audioSource="http://media.blubrry.com/burr/traffic.libsyn.com/billburr/MMPC_7-21-14.mp3"
- timeBegins="105"
- timeEnds="110">
- Start MMP - mp3 - 1:45 to 1:50
- </button>
- <br>
- <button class="btn btn-primary start-button"
- audioSource="http://media.blubrry.com/burr/traffic.libsyn.com/billburr/MMPC_7-21-14.mp3"
- timeBegins="3600"
- timeEnds="3605">
- Start MMP - mp3 - 1:00:00 to 1:00:05
- </button>
- <br>
- <button class="btn btn-primary start-button"
- audioSource="http://media.blubrry.com/burr/traffic.libsyn.com/billburr/MMPC_7-21-14.mp3"
- timeBegins="1800"
- timeEnds="1805">
- Start MMP - mp3 - 30:00 to 30:05
- </button>
- <br><br>
- <button class="btn btn-primary start-button"
- audioSource="http://traffic.libsyn.com/joeroganexp/p523.mp3"
- timeBegins="100"
- timeEnds="105">
- Start JRE #523 - mp3 - 1:40 to 1:45
- </button>
- <br>
- <button class="btn btn-primary start-button"
- audioSource="http://traffic.libsyn.com/joeroganexp/p523.mp3"
- timeBegins="3600"
- timeEnds="3605">
- Start JRE #523 - mp3 - 1:00:00 to 1:00:05
- </button>
- <br>
- <button class="btn btn-primary start-button"
- audioSource="http://traffic.libsyn.com/joeroganexp/p523.mp3"
- timeBegins="1800"
- timeEnds="1805">
- Start JRE #523 - mp3 - 30:00 to 30:05
- </button>
- <br><br>
- <button class="btn btn-primary start-button"
- audioSource="http://www.tuxradar.com/files/podcast/tuxradar_s06e02.ogg"
- timeBegins="200"
- timeEnds="205">
- TuxRadar Linux Podcast - ogg - 3:20 to 3:25
- </button>
- <br>
- <button class="btn btn-primary start-button"
- audioSource="http://www.tuxradar.com/files/podcast/tuxradar_s06e02.ogg"
- timeBegins="1000"
- timeEnds="1005">
- TuxRadar Linux Podcast - ogg - 16:40 to 16:45
- </button>
- <br>
- <button class="btn btn-primary start-button"
- audioSource="http://www.tuxradar.com/files/podcast/tuxradar_s06e02.ogg"
- timeBegins="1500"
- timeEnds="1505">
- TuxRadar Linux Podcast - ogg - 25:00 to 25:05
- </button>
- <br><br>
- <button class="btn btn-primary start-button"
- audioSource="http://www.linuxvoice.com/episodes/lv_s02e13.ogg"
- timeBegins="200"
- timeEnds="205">
- Linux Voice - ogg - 3:20 to 3:25
- </button>
- <br>
- <button class="btn btn-primary start-button"
- audioSource="http://www.linuxvoice.com/episodes/lv_s02e13.ogg"
- timeBegins="3600"
- timeEnds="3605">
- Linux Voice - ogg - 1:00:00 to 1:00:05
- </button>
- <br>
- <button class="btn btn-primary start-button"
- audioSource="http://www.linuxvoice.com/episodes/lv_s02e13.ogg"
- timeBegins="1000"
- timeEnds="1005">
- Linux Voice - ogg - 16:40 to 16:45
- </button>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement