1$(function() { 2 3 soundManager.setup({ 4 url: '/static/js/libs/soundmanager2/' 5 }); 6 7 $.widget( "ui.audioplayer", { 8 _create: function() { 9 var self = this; 10 11 self.$item = $(self.element); 12 13 self.play = $('[data-audio="play"]', self.$item); 14 self.mute = $('[data-audio="mute"]', self.$item); 15 self.volume = $('[data-audio="volume"]', self.$item); 16 self.progress = $('[data-audio="progress"]', self.$item); 17 self.time_current = $('[data-audio="time-current"]', self.$item); 18 self.time = $('[data-audio="time"]', self.$item); 19 20 var options = self.$item.data('options'); 21 22 self.createSound(options); 23 24 self.progress.slider({ 25 range: 'min', 26 min: 0, 27 max: 1000, 28 start: function() { 29 self.progress.slider('option', {changeIgnore: true}); 30 }, 31 stop: function() { 32 self.progress.slider('option', {changeIgnore: false}); 33 }, 34 change: function(e, ui){ 35 36 if (this.draggable || typeof e.handleObj === 'undefined') { 37 return true; 38 } 39 var pos = Math.round(ui.value / 1000 * self.getDurationEstimate(self.sound)); 40 41 self.sound.setPosition(pos); 42 if (self.sound.paused || self.sound.playState == 0) { 43 self.sound.togglePause(); 44 } 45 return true; 46 } 47 }); 48 49 self.volume.slider({ 50 range: 'min', 51 min: 0, 52 max: 100, 53 value: 50, 54 slide: function(e, ui){ 55 self.sound.setVolume(ui.value) 56 } 57 }); 58 59 self.bindHandlers(); 60 }, 61 getDurationEstimate: function(oSound) { 62 return (oSound.duration); 63 }, 64 getTime: function(nMSec, bAsString) { 65 // convert milliseconds to mm:ss, return as object literal or string 66 var nSec = Math.floor(nMSec/1000), 67 min = Math.floor(nSec/60), 68 sec = nSec-(min*60); 69 // if (min === 0 && sec === 0) return null; // return 0:00 as null 70 return (bAsString?((min<10?'0'+min:min)+':'+(sec<10?'0'+sec:sec)):{'min':min,'sec':sec}); 71 }, 72 createSound: function(opt) { 73 var self = this; 74 self.sound = soundManager.createSound({ 75 id: "sound_"+new Date().getTime(), 76 url: opt.url, 77 volume:50, 78 // autoPlay: true, 79 onload: function(){ 80 self.time.text(self.getTime(self.getDurationEstimate(self.sound), true)); 81 }, 82 onpause: function() { 83 self.play.removeClass('pause'); 84 }, 85 onresume: function() { 86 self._play(); 87// self.play.addClass('pause'); 88 }, 89 onplay: function() { 90 self._play(); 91// self.play.addClass('pause'); 92 }, 93 onfinish: function() { 94 self._stop(); 95 }, 96 onstop: function() { 97 self._stop(); 98 }, 99 whileplaying: function() { 100 var pos = self.sound.position, 101 duration = self.getDurationEstimate(self.sound); 102 103 self.time_current.text(self.getTime(pos, true)); 104 if (!self.progress.slider('option').changeIgnore) { 105 self.progress.slider({'value': Math.round(pos / duration * 1000)}); 106 } 107 } 108 }); 109 }, 110 _stop: function(){ 111 var self = this; 112 self.play.removeClass('pause'); 113 self.$item.removeClass('active'); 114 self.progress.slider({'value': 0}) 115 }, 116 _play: function(){ 117 var self = this; 118 self.$item.trigger('playSound', self.sound.id); 119 self.play.addClass('pause'); 120 self.$item.addClass('active'); 121 }, 122 bindHandlers: function() { 123 var self = this; 124 125 $('body').on('playSound', function(e, id){ 126 if(self.sound.id != id && self.sound.playState != 0) { 127 self.sound.stop(); 128 } 129 }); 130 131 self.play.on('click', function() { 132 self.sound.togglePause(); 133 }); 134 135 self.mute.on('click', function() { 136 self.sound.toggleMute(); 137 if(self.sound.muted) { 138 self.mute.addClass('off'); 139 } else { 140 self.mute.removeClass('off'); 141 } 142 }); 143 } 144 }); 145});
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.