Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Get IE or Edge browser version
- var IEVersion = detectIE();
- /**
- * detect IE
- * returns version of IE or false, if browser is not Internet Explorer
- */
- function detectIE() {
- var ua = window.navigator.userAgent;
- // IE 10
- // ua = 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0)';
- // IE 11
- // ua = 'Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko';
- // Edge 12 (Spartan)
- // ua = 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36 Edge/12.0';
- // Edge 13
- // ua = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2486.0 Safari/537.36 Edge/13.10586';
- var msie = ua.indexOf('MSIE ');
- if (msie > 0) {
- // IE 10 or older => return version number
- return parseInt(ua.substring(msie + 5, ua.indexOf('.', msie)), 10);
- }
- var trident = ua.indexOf('Trident/');
- if (trident > 0) {
- // IE 11 => return version number
- var rv = ua.indexOf('rv:');
- return parseInt(ua.substring(rv + 3, ua.indexOf('.', rv)), 10);
- }
- var edge = ua.indexOf('Edge/');
- if (edge > 0) {
- // Edge (IE 12+) => return version number
- return parseInt(ua.substring(edge + 5, ua.indexOf('.', edge)), 10);
- }
- // other browser
- return false;
- }
- if(IEVersion > 12)
- var SoundManager = (function () {
- window.AudioContext = window.AudioContext || window.webkitAudioContext;
- /// custom buffer loader
- /// see http://www.html5rocks.com/en/tutorials/webaudio/intro/
- function BufferLoader(context, urlList, callback) {
- this.context = context;
- this.urlList = urlList;
- this.onload = callback;
- this.bufferList = new Array();
- this.loadCount = 0;
- }
- BufferLoader.prototype.loadBuffer = function (url, index) {
- // Load buffer asynchronously
- var request = new XMLHttpRequest();
- request.open("GET", url, true);
- request.responseType = "arraybuffer";
- var loader = this;
- request.onload = function () {
- // Asynchronously decode the audio file data in request.response
- loader.context.decodeAudioData(
- request.response,
- function (buffer) {
- if (!buffer) {
- alert('error decoding file data: ' + url);
- return;
- }
- loader.bufferList[index] = buffer;
- if (++loader.loadCount == loader.urlList.length) loader.onload(loader.bufferList);
- },
- function (error) {
- console.error('decodeAudioData error', error);
- });
- }
- request.onerror = function (e) {
- alert('BufferLoader: XHR error');
- console.log(e);
- }
- request.send();
- }
- BufferLoader.prototype.load = function () {
- for (var i = 0; i < this.urlList.length; ++i)
- this.loadBuffer(this.urlList[i], i);
- }
- /// setup audio context and start loading samples
- var actx = new AudioContext(),
- blst,
- bLoader = new BufferLoader(
- actx, [
- window.location.origin + '/mobile/sounds/closeToYou.wav',
- window.location.origin + '/mobile/sounds/arrivedAtLocation.wav',
- ],
- done),
- isReady = false;
- /// start loading the samples
- bLoader.load();
- /// when samples are loaded update status
- function done(bl) {
- blst = bl;
- isReady = true;
- $('#status').html('Ready!');
- }
- /// this sets up chain so we can play audio
- function play(i) {
- var src = actx.createBufferSource();
- src.buffer = blst[i];
- src.connect(actx.destination);
- src.start(0);
- }
- this.playCloseToMeLocation = function () {
- play(0);
- };
- this.playArrivedAtLocation = function () {
- play(1);
- };
- return this;
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement