diff --git a/dancer.js b/dancer.js index 847fdba..b2b3ea7 100644 --- a/dancer.js +++ b/dancer.js @@ -1,4 +1,4 @@ -/* dancer.js - v0.3.2 - 2012-09-29 +/* dancer.js - v0.3.2 - 2012-12-07 * https://github.com/jsantell/dancer.js * Copyright (c) 2012 Jordan Santell; Licensed MIT */ @@ -401,7 +401,7 @@ } this.audio.addEventListener( 'progress', function ( e ) { - if ( e.currentTarget.duration ) { + if ( e.currentTarget.duration && ( e.currentTarget.seekable.length > 0 )) { _this.progress = e.currentTarget.seekable.end( 0 ) / e.currentTarget.duration; } }); diff --git a/dancer.min.js b/dancer.min.js index 6272411..4efe917 100644 --- a/dancer.min.js +++ b/dancer.min.js @@ -1,4 +1,4 @@ -/* dancer.js - v0.3.2 - 2012-09-29 +/* dancer.js - v0.3.2 - 2012-12-07 * https://github.com/jsantell/dancer.js * Copyright (c) 2012 Jordan Santell; Licensed MIT */ -function FourierTransform(e,t){this.bufferSize=e,this.sampleRate=t,this.bandwidth=2/e*t/2,this.spectrum=new Float32Array(e/2),this.real=new Float32Array(e),this.imag=new Float32Array(e),this.peakBand=0,this.peak=0,this.getBandFrequency=function(e){return this.bandwidth*e+this.bandwidth/2},this.calculateSpectrum=function(){var t=this.spectrum,n=this.real,r=this.imag,i=2/this.bufferSize,s=Math.sqrt,o,u,a;for(var f=0,l=e/2;fthis.peak&&(this.peakBand=f,this.peak=a),t[f]=a}}function FFT(e,t){FourierTransform.call(this,e,t),this.reverseTable=new Uint32Array(e);var n=1,r=e>>1,i;while(n>=1}this.sinTable=new Float32Array(e),this.cosTable=new Float32Array(e);for(i=0;ie},callback:t}),this},before:function(e,t){var n=this;return this.sections.push({condition:function(){return n.getTime()e&&r.getTime()e&&!this.called},callback:function(){t.call(this),r.called=!0},called:!1}),r=this.sections[this.sections.length-1],this}},window.Dancer=e})(),function(e){function r(){var e=!!(navigator.vendor||"").match(/Apple/),t=navigator.userAgent.match(/Version\/([^ ]*)/);return t=t?parseFloat(t[1]):0,e&&t<=6}var t={mp3:"audio/mpeg;",ogg:'audio/ogg; codecs="vorbis"',wav:'audio/wav; codecs="1"',aac:'audio/mp4; codecs="mp4a.40.2"'},n=document.createElement("audio");e.options={},e.setOptions=function(t){for(var n in t)t.hasOwnProperty(n)&&(e.options[n]=t[n])},e.isSupported=function(){return!window.Float32Array||!window.Uint32Array?null:!r()&&(window.AudioContext||window.webkitAudioContext)?"webaudio":n&&n.mozSetup?"audiodata":FlashDetect.versionAtLeast(9)?"flash":""},e.canPlay=function(r){var i=n.canPlayType;return e.isSupported()==="flash"?r.toLowerCase()==="mp3":!!n.canPlayType&&!!n.canPlayType(t[r.toLowerCase()]).replace(/no/,"")},e.addPlugin=function(t,n){e.prototype[t]===undefined&&(e.prototype[t]=n)},e._makeSupportedPath=function(t,n){if(!n)return t;for(var r=0;r=this.currentThreshold&&e>=this.threshold?(this.currentThreshold=e,this.onKick&&this.onKick.call(this.dancer,e)):(this.offKick&&this.offKick.call(this.dancer,e),this.currentThreshold-=this.decay)},maxAmplitude:function(e){var t=0,n=this.dancer.getSpectrum();if(!e.length)return et&&(t=n[r]);return t}},window.Dancer.Kick=t}(),function(){function r(){this.source=this.context.createMediaElementSource(this.audio),this.source.connect(this.proc),this.source.connect(this.gain),this.gain.connect(this.context.destination),this.proc.connect(this.context.destination),this.isLoaded=!0,this.progress=1,this.dancer.trigger("loaded")}var e=2048,t=44100,n=function(e){this.dancer=e,this.audio=new Audio,this.context=window.AudioContext?new window.AudioContext:new window.webkitAudioContext};n.prototype={load:function(n){var i=this;return this.audio=n,this.isLoaded=!1,this.progress=0,this.proc=this.context.createJavaScriptNode(e/2,1,1),this.proc.onaudioprocess=function(e){i.update.call(i,e)},this.gain=this.context.createGainNode(),this.fft=new FFT(e/2,t),this.signal=new Float32Array(e/2),this.audio.readyState<3?this.audio.addEventListener("canplay",function(){r.call(i)}):r.call(i),this.audio.addEventListener("progress",function(e){e.currentTarget.duration&&(i.progress=e.currentTarget.seekable.end(0)/e.currentTarget.duration)}),this.audio},play:function(){this.audio.play(),this.isPlaying=!0},pause:function(){this.audio.pause(),this.isPlaying=!1},setVolume:function(e){this.gain.gain.value=e},getVolume:function(){return this.gain.gain.value},getProgress:function(){return this.progress},getWaveform:function(){return this.signal},getSpectrum:function(){return this.fft.spectrum},getTime:function(){return this.audio.currentTime},update:function(t){if(!this.isPlaying||!this.isLoaded)return;var n=[],r=t.inputBuffer.numberOfChannels,i=e/r,s=function(e,t){return e[o]+t[o]},o;for(o=r;o--;)n.push(t.inputBuffer.getChannelData(o));for(o=0;o1?n.reduce(s)/r:n[0][o];this.fft.forward(this.signal),this.dancer.trigger("update")}},Dancer.adapters.webkit=n}(),function(){function t(){this.fbLength=this.audio.mozFrameBufferLength,this.channels=this.audio.mozChannels,this.rate=this.audio.mozSampleRate,this.fft=new FFT(this.fbLength/this.channels,this.rate),this.signal=new Float32Array(this.fbLength/this.channels),this.isLoaded=!0,this.progress=1,this.dancer.trigger("loaded")}var e=function(e){this.dancer=e,this.audio=new Audio};e.prototype={load:function(e){var n=this;return this.audio=e,this.isLoaded=!1,this.progress=0,this.audio.readyState<3?this.audio.addEventListener("loadedmetadata",function(){t.call(n)},!1):t.call(n),this.audio.addEventListener("MozAudioAvailable",function(e){n.update(e)},!1),this.audio.addEventListener("progress",function(e){e.currentTarget.duration&&(n.progress=e.currentTarget.seekable.end(0)/e.currentTarget.duration)},!1),this.audio},play:function(){this.audio.play(),this.isPlaying=!0},pause:function(){this.audio.pause(),this.isPlaying=!1},setVolume:function(e){this.audio.volume=e},getVolume:function(){return this.audio.volume},getProgress:function(){return this.progress},getWaveform:function(){return this.signal},getSpectrum:function(){return this.fft.spectrum},getTime:function(){return this.audio.currentTime},update:function(e){if(!this.isPlaying||!this.isLoaded)return;for(var t=0,n=this.fbLength/2;t=t},e.minorAtLeast=function(t){return e.minor>=t},e.revisionAtLeast=function(t){return e.revision>=t},e.versionAtLeast=function(t){var n=[e.major,e.minor,e.revision],r=Math.min(n.length,arguments.length);for(i=0;i=arguments[i]){if(i+10){var n="application/x-shockwave-flash",i=navigator.mimeTypes;if(i&&i[n]&&i[n].enabledPlugin&&i[n].enabledPlugin.description){var u=i[n].enabledPlugin.description,a=o(u);e.raw=a.raw,e.major=a.major,e.minor=a.minor,e.revisionStr=a.revisionStr,e.revision=a.revision,e.installed=!0}}else if(navigator.appVersion.indexOf("Mac")==-1&&window.execScript){var u=-1;for(var f=0;fthis.peak&&(this.peakBand=f,this.peak=a),t[f]=a}}function FFT(e,t){FourierTransform.call(this,e,t),this.reverseTable=new Uint32Array(e);var n=1,r=e>>1,i;while(n>=1}this.sinTable=new Float32Array(e),this.cosTable=new Float32Array(e);for(i=0;ie},callback:t}),this},before:function(e,t){var n=this;return this.sections.push({condition:function(){return n.getTime()e&&r.getTime()e&&!this.called},callback:function(){t.call(this),r.called=!0},called:!1}),r=this.sections[this.sections.length-1],this}},window.Dancer=e})(),function(e){function r(){var e=!!(navigator.vendor||"").match(/Apple/),t=navigator.userAgent.match(/Version\/([^ ]*)/);return t=t?parseFloat(t[1]):0,e&&t<=6}var t={mp3:"audio/mpeg;",ogg:'audio/ogg; codecs="vorbis"',wav:'audio/wav; codecs="1"',aac:'audio/mp4; codecs="mp4a.40.2"'},n=document.createElement("audio");e.options={},e.setOptions=function(t){for(var n in t)t.hasOwnProperty(n)&&(e.options[n]=t[n])},e.isSupported=function(){return!window.Float32Array||!window.Uint32Array?null:!r()&&(window.AudioContext||window.webkitAudioContext)?"webaudio":n&&n.mozSetup?"audiodata":FlashDetect.versionAtLeast(9)?"flash":""},e.canPlay=function(r){var i=n.canPlayType;return e.isSupported()==="flash"?r.toLowerCase()==="mp3":!!n.canPlayType&&!!n.canPlayType(t[r.toLowerCase()]).replace(/no/,"")},e.addPlugin=function(t,n){e.prototype[t]===undefined&&(e.prototype[t]=n)},e._makeSupportedPath=function(t,n){if(!n)return t;for(var r=0;r=this.currentThreshold&&e>=this.threshold?(this.currentThreshold=e,this.onKick&&this.onKick.call(this.dancer,e)):(this.offKick&&this.offKick.call(this.dancer,e),this.currentThreshold-=this.decay)},maxAmplitude:function(e){var t=0,n=this.dancer.getSpectrum();if(!e.length)return et&&(t=n[r]);return t}},window.Dancer.Kick=t}(),function(){function r(){this.source=this.context.createMediaElementSource(this.audio),this.source.connect(this.proc),this.source.connect(this.gain),this.gain.connect(this.context.destination),this.proc.connect(this.context.destination),this.isLoaded=!0,this.progress=1,this.dancer.trigger("loaded")}var e=2048,t=44100,n=function(e){this.dancer=e,this.audio=new Audio,this.context=window.AudioContext?new window.AudioContext:new window.webkitAudioContext};n.prototype={load:function(n){var i=this;return this.audio=n,this.isLoaded=!1,this.progress=0,this.proc=this.context.createJavaScriptNode(e/2,1,1),this.proc.onaudioprocess=function(e){i.update.call(i,e)},this.gain=this.context.createGainNode(),this.fft=new FFT(e/2,t),this.signal=new Float32Array(e/2),this.audio.readyState<3?this.audio.addEventListener("canplay",function(){r.call(i)}):r.call(i),this.audio.addEventListener("progress",function(e){e.currentTarget.duration&&e.currentTarget.seekable.length>0&&(i.progress=e.currentTarget.seekable.end(0)/e.currentTarget.duration)}),this.audio},play:function(){this.audio.play(),this.isPlaying=!0},pause:function(){this.audio.pause(),this.isPlaying=!1},setVolume:function(e){this.gain.gain.value=e},getVolume:function(){return this.gain.gain.value},getProgress:function(){return this.progress},getWaveform:function(){return this.signal},getSpectrum:function(){return this.fft.spectrum},getTime:function(){return this.audio.currentTime},update:function(t){if(!this.isPlaying||!this.isLoaded)return;var n=[],r=t.inputBuffer.numberOfChannels,i=e/r,s=function(e,t){return e[o]+t[o]},o;for(o=r;o--;)n.push(t.inputBuffer.getChannelData(o));for(o=0;o1?n.reduce(s)/r:n[0][o];this.fft.forward(this.signal),this.dancer.trigger("update")}},Dancer.adapters.webkit=n}(),function(){function t(){this.fbLength=this.audio.mozFrameBufferLength,this.channels=this.audio.mozChannels,this.rate=this.audio.mozSampleRate,this.fft=new FFT(this.fbLength/this.channels,this.rate),this.signal=new Float32Array(this.fbLength/this.channels),this.isLoaded=!0,this.progress=1,this.dancer.trigger("loaded")}var e=function(e){this.dancer=e,this.audio=new Audio};e.prototype={load:function(e){var n=this;return this.audio=e,this.isLoaded=!1,this.progress=0,this.audio.readyState<3?this.audio.addEventListener("loadedmetadata",function(){t.call(n)},!1):t.call(n),this.audio.addEventListener("MozAudioAvailable",function(e){n.update(e)},!1),this.audio.addEventListener("progress",function(e){e.currentTarget.duration&&(n.progress=e.currentTarget.seekable.end(0)/e.currentTarget.duration)},!1),this.audio},play:function(){this.audio.play(),this.isPlaying=!0},pause:function(){this.audio.pause(),this.isPlaying=!1},setVolume:function(e){this.audio.volume=e},getVolume:function(){return this.audio.volume},getProgress:function(){return this.progress},getWaveform:function(){return this.signal},getSpectrum:function(){return this.fft.spectrum},getTime:function(){return this.audio.currentTime},update:function(e){if(!this.isPlaying||!this.isLoaded)return;for(var t=0,n=this.fbLength/2;t=t},e.minorAtLeast=function(t){return e.minor>=t},e.revisionAtLeast=function(t){return e.revision>=t},e.versionAtLeast=function(t){var n=[e.major,e.minor,e.revision],r=Math.min(n.length,arguments.length);for(i=0;i=arguments[i]){if(i+10){var n="application/x-shockwave-flash",i=navigator.mimeTypes;if(i&&i[n]&&i[n].enabledPlugin&&i[n].enabledPlugin.description){var u=i[n].enabledPlugin.description,a=o(u);e.raw=a.raw,e.major=a.major,e.minor=a.minor,e.revisionStr=a.revisionStr,e.revision=a.revision,e.installed=!0}}else if(navigator.appVersion.indexOf("Mac")==-1&&window.execScript){var u=-1;for(var f=0;f 0 )) { _this.progress = e.currentTarget.seekable.end( 0 ) / e.currentTarget.duration; } });