1(function($) { 2 "use strict"; 3 4 $(window).on('load', function() { 5 $(".audioPlayer") 6 .toArray() 7 .forEach(function(player) { 8 /**find the audio tag */ 9 10 var audio = $(player).find("audio")[0]; 11 var seekbarInner = $(player).find(".seekBar .inner"); 12 var seekbarOuter = $(player).find(".seekBar .outer"); 13 var volumeControl = $(player).find(".volumeControl .wrapper"); 14 var length; 15 var interval; 16 var seekBarPercentage; 17 var volumePercentage; 18 var minutes = parseInt(audio.duration / 60, 10); 19 var seconds = parseInt(audio.duration % 60); 20 21 /** set the end duration **/ 22 $(player).find(".timing .end").text(minutes + ":" + seconds); 23 24 /**************************** All Functions ************************/ 25 26 /**Find Percentage */ 27 var getPercentage = function(presentTime, totalLength) { 28 var calcPercentage = (presentTime / totalLength) * 100; 29 return parseFloat(calcPercentage.toString()); 30 }; 31 /** 32 * Update seekBars 33 * */ 34 var updateSeekBar = function() { 35 seekBarPercentage = getPercentage( 36 audio.currentTime.toFixed(2), 37 length.toFixed(2) 38 ); 39 40 /**update the seek bar percentage */ 41 $(seekbarInner).css("width", seekBarPercentage + "%"); 42 43 /**update the start time **/ 44 $(player) 45 .find(".timing .start") 46 .text(parseInt(audio.currentTime / 60, 10) + ':' + parseInt(audio.currentTime % 60)); 47 }; 48 49 /************************ on click of button playing the song *************************/ 50 $(player) 51 .find(".btn") 52 .on("click", function() { 53 var _button = $(this); 54 /**if the button has class play then */ 55 if (_button.hasClass("play")) { 56 _button.removeClass("play").addClass("pause"); 57 58 /**find length of audio */ 59 length = audio.duration; 60 61 /**** play the audio ****/ 62 audio.play(); 63 64 /**set seekbar percentage */ 65 interval = setInterval(function() { 66 67 68 /**run this function to update seekbar */ 69 if (!audio.paused) { 70 /*check wheather audio is playing then*/ 71 updateSeekBar(); 72 } 73 74 /**if audio playback ended */ 75 if (audio.ended) { 76 clearInterval(interval); 77 $(player) 78 .find(".albumArt"); 79 _button.removeClass("pause").addClass("play"); 80 seekbarInner.width(100 + "%"); 81 82 $(player) 83 .find(".timing .start") 84 .text('0:00'); 85 } 86 }, 1000); 87 } else if (_button.hasClass("pause")) { 88 _button.removeClass("pause").addClass("play"); 89 audio.pause(); 90 } 91 92 /**animating album art */ 93 $(player).find(".albumArt") 94 }); 95 96 /****************for click on scroll bar **************************/ 97 seekbarOuter.on("click", function(e) { 98 if (!audio.ended && length !== undefined) { 99 var seekPosition = e.pageX - $(seekbarOuter).offset().left; 100 if (seekPosition >= 0) { 101 audio.currentTime = (seekPosition * audio.duration) / $(seekbarOuter).width(); 102 updateSeekBar(); 103 } 104 } 105 }); 106 107 /**************** for click on volume control ******************/ 108 volumeControl.find(".outer").on("click", function(e) { 109 var volumePosition = e.pageX - $(this).offset().left; 110 var audioVolume = volumePosition / $(this).width(); 111 if (audioVolume >= 0 && audioVolume <= 1) { 112 audio.volume = audioVolume; 113 $(this)
114 .find(".inner") 115 .css("width", audioVolume * 100 + "%"); 116 } 117 }); 118 119 120 121 /** 122 * update volumeBar 123 **/ 124 var updateVolume = function() { 125 volumePercentage = getPercentage(audio.volume, 1); 126 $(volumeControl) 127 .find(".inner") 128 .css("width", volumePercentage + "%"); 129 }; 130 131 /**forEach End**/ 132 }); 133 134 }); 135})(jQuery);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.