-
Notifications
You must be signed in to change notification settings - Fork 257
/
Copy pathaudiostreamsource.min.js
6 lines (6 loc) · 1.91 KB
/
audiostreamsource.min.js
1
2
3
4
5
6
/**
* @license audiostreamsource.js 0.0.2 Copyright (c) 2015, Gregg Tavares All Rights Reserved.
* Available via the MIT license.
* see: http://github.com/greggman/audiostreamsource.js for details
*/
!function(a,b){"function"==typeof define&&define.amd&&define([],b),"undefined"!=typeof module&&module.exports?module.exports=b():a.audioStreamSource=b()}(this,function(){function a(a){var b={};return a.on=function(a,c){b[a]=c},emit=function(a){var c=b[a];c&&c.apply(null,Array.prototype.slice.call(arguments,1))}}function b(a,b){a()}function c(c){function d(a){m=!1,l.src=a,l.load()}function e(){return h}function f(){l.play(),l.currentTime=0}function g(){return!l.paused}var h,i=a(this),j=c.context,k=c.autoPlay,l=new Audio,m=!1,n=function(a){i("error",a)},o=function(){m||(m=!0,h&&h.disconnect(),k&&b(f,i),h||(h=j.createMediaElementSource(l)),i("newSource",h))};l.addEventListener("error",n),l.addEventListener("canplay",o),l.loop=c.loop,l.autoplay=c.autoPlay,void 0!==c.crossOrigin&&(l.crossOrigin="anonymous"),c.src&&d(c.src),this.isPlaying=g,this.play=function(){b(f,i)},this.stop=function(){l.pause()},this.setSource=d,this.getSource=e}function d(c){function d(){i&&i.start(0),o=!0}function e(){i&&i.stop(0),o=!1}function f(){return o}function g(a,c){i&&(e(),i.disconnect(),i=void 0);var f=new XMLHttpRequest;f.open("GET",c||a,!0),f.responseType="arraybuffer",void 0!==n&&(f.withCredentials=!0),f.addEventListener("error",function(a){j("error",a)}),f.addEventListener("load",function(){k.decodeAudioData(f.response,function(a){i=k.createBufferSource(),i.buffer=a,i.loop=l,m&&b(d,j),j("newSource",i)})}),f.send()}function h(){return i}var i,j=a(this),k=c.context,l=c.loop,m=c.autoPlay,n=c.crossOrigin,o=!1;c.src&&g(c.src,c.lofiSrc),this.getSource=h,this.setSource=g,this.play=d,this.stop=e,this.isPlaying=f}function e(a){return new(f?d:c)(a)}var f=void 0===window.AudioContext&&/iPhone|iPad|iPod/.test(navigator.userAgent);return{create:e}});