﻿(function (window) { var soundManager = null; function SoundManager(smURL, smID) { this.flashVersion = 8; this.debugMode = true; this.debugFlash = false; this.useConsole = true; this.consoleOnly = false; this.waitForWindowLoad = false; this.nullURL = "about:blank"; this.allowPolling = true; this.useFastPolling = false; this.useMovieStar = true; this.bgColor = "#ffffff"; this.useHighPerformance = false; this.flashPollingInterval = null; this.flashLoadTimeout = 1000; this.wmode = null; this.allowScriptAccess = "always"; this.useFlashBlock = false; this.useHTML5Audio = false; this.html5Test = /^probably$/i; this.ondebuglog = false; this.audioFormats = { mp3: { type: ['audio/mpeg; codecs="mp3"', "audio/mpeg", "audio/mp3", "audio/MPA", "audio/mpa-robust"], required: true }, mp4: { related: ["aac", "m4a"], type: ['audio/mp4; codecs="mp4a.40.2"', "audio/aac", "audio/x-m4a", "audio/MP4A-LATM", "audio/mpeg4-generic"], required: true }, ogg: { type: ["audio/ogg; codecs=vorbis"], required: false }, wav: { type: ['audio/wav; codecs="1"', "audio/wav", "audio/wave", "audio/x-wav"], required: false} }; this.defaultOptions = { autoLoad: false, stream: true, autoPlay: false, loops: 1, onid3: null, onload: null, whileloading: null, onplay: null, onpause: null, onresume: null, whileplaying: null, onstop: null, onfailure: null, onfinish: null, onbeforefinish: null, onbeforefinishtime: 5000, onbeforefinishcomplete: null, onjustbeforefinish: null, onjustbeforefinishtime: 200, multiShot: true, multiShotEvents: false, position: null, pan: 0, type: null, usePolicyFile: false, volume: 100 }; this.flash9Options = { isMovieStar: null, usePeakData: false, useWaveformData: false, useEQData: false, onbufferchange: null, ondataerror: null, onstats: null }; this.movieStarOptions = { bufferTime: 3, serverURL: null, onconnect: null, bufferTimes: null, duration: null }; this.version = null; this.versionNumber = "V2.97a.20110101"; this.movieURL = null; this.url = (smURL || null); this.altURL = null; this.swfLoaded = false; this.enabled = false; this.o = null; this.movieID = "sm2-container"; this.id = (smID || "sm2movie"); this.swfCSS = { swfBox: "sm2-object-box", swfDefault: "movieContainer", swfError: "swf_error", swfTimedout: "swf_timedout", swfUnblocked: "swf_unblocked", sm2Debug: "sm2_debug", highPerf: "high_performance", flashDebug: "flash_debug" }; this.oMC = null; this.sounds = {}; this.soundIDs = []; this.muted = false; this.debugID = "soundmanager-debug"; this.debugURLParam = /([#?&])debug=1/i; this.specialWmodeCase = false; this.didFlashBlock = false; this.filePattern = null; this.filePatterns = { flash8: /\.mp3(\?.*)?$/i, flash9: /\.mp3(\?.*)?$/i }; this.baseMimeTypes = /^\s*audio\/(?:x-)?(?:mp(?:eg|3))\s*(?:$|;)/i; this.netStreamMimeTypes = /^\s*audio\/(?:x-)?(?:mp(?:eg|3))\s*(?:$|;)/i; this.netStreamTypes = ["aac", "flv", "mov", "mp4", "m4v", "f4v", "m4a", "mp4v", "3gp", "3g2"]; this.netStreamPattern = new RegExp("\\.(" + this.netStreamTypes.join("|") + ")(\\?.*)?$", "i"); this.mimePattern = this.baseMimeTypes; this.features = { buffering: false, peakData: false, waveformData: false, eqData: false, movieStar: false }; this.sandbox = { type: null, types: { remote: "remote (domain-based) rules", localWithFile: "local with file access (no internet access)", localWithNetwork: "local with network (internet access only, no local access)", localTrusted: "local, trusted (local+internet access)" }, description: null, noRemote: null, noLocal: null }; this.hasHTML5 = null; this.html5 = { usingFlash: null }; this.ignoreFlash = false; var SMSound, _s = this, _sm = "soundManager", _id, _ua = navigator.userAgent, _wl = window.location.href.toString(), _fV = this.flashVersion, _doc = document, _win = window, _doNothing, _init, _on_queue = [], _debugOpen = true, _debugTS, _didAppend = false, _appendSuccess = false, _didInit = false, _disabled = false, _windowLoaded = false, _wDS, _wdCount = 0, _initComplete, _mixin, _addOnEvent, _processOnEvents, _initUserOnload, _go, _delayWaitForEI, _waitForEI, _setVersionInfo, _handleFocus, _beginInit, _strings, _initMovie, _dcLoaded, _didDCLoaded, _getDocument, _createMovie, _die, _setPolling, _debugLevels = ["log", "info", "warn", "error"], _defaultFlashVersion = 8, _disableObject, _failSafely, _normalizeMovieURL, _oRemoved = null, _oRemovedHTML = null, _str, _flashBlockHandler, _getSWFCSS, _toggleDebug, _loopFix, _policyFix, _complain, _idCheck, _waitingForEI = false, _initPending = false, _smTimer, _onTimer, _startTimer, _stopTimer, _needsFlash = null, _featureCheck, _html5OK, _html5Only = false, _html5CanPlay, _html5Ext, _dcIE, _testHTML5, _event, _slice = Array.prototype.slice, _is_pre = _ua.match(/pre\//i), _is_iDevice = _ua.match(/(ipad|iphone|ipod)/i), _isMobile = (_ua.match(/mobile/i) || _is_pre || _is_iDevice), _isIE = _ua.match(/MSIE/i), _isWebkit = _ua.match(/webkit/i), _isSafari = (_ua.match(/safari/i) && !_ua.match(/chrome/i)), _hasConsole = (typeof console !== "undefined" && typeof console.log !== "undefined"), _isFocused = (typeof _doc.hasFocus !== "undefined" ? _doc.hasFocus() : null), _tryInitOnFocus = (typeof _doc.hasFocus === "undefined" && _isSafari), _okToDisable = !_tryInitOnFocus; this._use_maybe = (_wl.match(/sm2\-useHTML5Maybe\=1/i)); this._overHTTP = (_doc.location ? _doc.location.protocol.match(/http/i) : null); this.useAltURL = !this._overHTTP; if (_is_iDevice || _is_pre) { _s.useHTML5Audio = true; _s.ignoreFlash = true; } if (_is_pre || this._use_maybe) { _s.html5Test = /^(probably|maybe)$/i; } (function () { var a = "#sm2-usehtml5audio=", l = _wl, b = null; if (l.indexOf(a) !== -1) { b = (l.substr(l.indexOf(a) + a.length) === "1"); if (typeof console !== "undefined" && typeof console.log !== "undefined") { console.log((b ? "Enabling " : "Disabling ") + "useHTML5Audio via URL parameter"); } _s.useHTML5Audio = b; } } ()); this.ok = function () { return (_needsFlash ? (_didInit && !_disabled) : (_s.useHTML5Audio && _s.hasHTML5)); }; this.supported = this.ok; this.getMovie = function (smID) { return _isIE ? _win[smID] : (_isSafari ? _id(smID) || _doc[smID] : _id(smID)); }; this.createSound = function (oOptions) { var _cs = "soundManager.createSound(): ", thisOptions = null, oSound = null, _tO = null; if (!_didInit || !_s.ok()) { _complain(_cs + _str(!_didInit ? "notReady" : "notOK")); return false; } if (arguments.length === 2) { oOptions = { id: arguments[0], url: arguments[1] }; } thisOptions = _mixin(oOptions); _tO = thisOptions; if (_tO.id.toString().charAt(0).match(/^[0-9]$/)) { _s._wD(_cs + _str("badID", _tO.id), 2); } _s._wD(_cs + _tO.id + " (" + _tO.url + ")", 1); if (_idCheck(_tO.id, true)) { _s._wD(_cs + _tO.id + " exists", 1); return _s.sounds[_tO.id]; } function make() { thisOptions = _loopFix(thisOptions); _s.sounds[_tO.id] = new SMSound(_tO); _s.soundIDs.push(_tO.id); return _s.sounds[_tO.id]; } if (_html5OK(_tO)) { oSound = make(); _s._wD("Loading sound " + _tO.id + " via HTML5"); oSound._setup_html5(_tO); } else { if (_fV > 8 && _s.useMovieStar) { if (_tO.isMovieStar === null) { _tO.isMovieStar = ((_tO.serverURL || (_tO.type ? _tO.type.match(_s.netStreamPattern) : false) || _tO.url.match(_s.netStreamPattern)) ? true : false); } if (_tO.isMovieStar) { _s._wD(_cs + "using MovieStar handling"); } if (_tO.isMovieStar) { if (_tO.usePeakData) { _wDS("noPeak"); _tO.usePeakData = false; } if (_tO.loops > 1) { _wDS("noNSLoop"); } } } _tO = _policyFix(_tO, _cs); oSound = make(); if (_fV === 8) { _s.o._createSound(_tO.id, _tO.onjustbeforefinishtime, _tO.loops || 1, _tO.usePolicyFile); } else { _s.o._createSound(_tO.id, _tO.url, _tO.onjustbeforefinishtime, _tO.usePeakData, _tO.useWaveformData, _tO.useEQData, _tO.isMovieStar, (_tO.isMovieStar ? _tO.bufferTime : false), _tO.loops || 1, _tO.serverURL, _tO.duration || null, _tO.autoPlay, true, _tO.bufferTimes, _tO.onstats ? true : false, _tO.autoLoad, _tO.usePolicyFile); if (!_tO.serverURL) { oSound.connected = true; if (_tO.onconnect) { _tO.onconnect.apply(oSound); } } } } if (_tO.autoLoad || _tO.autoPlay) { if (oSound) { if (_s.isHTML5) { oSound.autobuffer = "auto"; oSound.preload = "auto"; } else { oSound.load(_tO); } } } if (_tO.autoPlay) { oSound.play(); } return oSound; }; this.destroySound = function (sID, _bFromSound) { if (!_idCheck(sID)) { return false; } var oS = _s.sounds[sID], i; oS._iO = {}; oS.stop(); oS.unload(); for (i = 0; i < _s.soundIDs.length; i++) { if (_s.soundIDs[i] === sID) { _s.soundIDs.splice(i, 1); break; } } if (!_bFromSound) { oS.destruct(true); } oS = null; delete _s.sounds[sID]; return true; }; this.load = function (sID, oOptions) { if (!_idCheck(sID)) { return false; } return _s.sounds[sID].load(oOptions); }; this.unload = function (sID) { if (!_idCheck(sID)) { return false; } return _s.sounds[sID].unload(); }; this.play = function (sID, oOptions) { var fN = "soundManager.play(): "; if (!_didInit || !_s.ok()) { _complain(fN + _str(!_didInit ? "notReady" : "notOK")); return false; } if (!_idCheck(sID)) { if (!(oOptions instanceof Object)) { oOptions = { url: oOptions }; } if (oOptions && oOptions.url) { _s._wD(fN + 'attempting to create "' + sID + '"', 1); oOptions.id = sID; return _s.createSound(oOptions).play(); } else { return false; } } return _s.sounds[sID].play(oOptions); }; this.start = this.play; this.setPosition = function (sID, nMsecOffset) { if (!_idCheck(sID)) { return false; } return _s.sounds[sID].setPosition(nMsecOffset); }; this.stop = function (sID) { if (!_idCheck(sID)) { return false; } _s._wD("soundManager.stop(" + sID + ")", 1); return _s.sounds[sID].stop(); }; this.stopAll = function () { _s._wD("soundManager.stopAll()", 1); for (var oSound in _s.sounds) { if (_s.sounds[oSound] instanceof SMSound) { _s.sounds[oSound].stop(); } } }; this.pause = function (sID) { if (!_idCheck(sID)) { return false; } return _s.sounds[sID].pause(); }; this.pauseAll = function () { for (var i = _s.soundIDs.length; i--; ) { _s.sounds[_s.soundIDs[i]].pause(); } }; this.resume = function (sID) { if (!_idCheck(sID)) { return false; } return _s.sounds[sID].resume(); }; this.resumeAll = function () { for (var i = _s.soundIDs.length; i--; ) { _s.sounds[_s.soundIDs[i]].resume(); } }; this.togglePause = function (sID) { if (!_idCheck(sID)) { return false; } return _s.sounds[sID].togglePause(); }; this.setPan = function (sID, nPan) { if (!_idCheck(sID)) { return false; } return _s.sounds[sID].setPan(nPan); }; this.setVolume = function (sID, nVol) { if (!_idCheck(sID)) { return false; } return _s.sounds[sID].setVolume(nVol); }; this.mute = function (sID) { var fN = "soundManager.mute(): ", i = 0; if (typeof sID !== "string") { sID = null; } if (!sID) { _s._wD(fN + "Muting all sounds"); for (i = _s.soundIDs.length; i--; ) { _s.sounds[_s.soundIDs[i]].mute(); } _s.muted = true; } else { if (!_idCheck(sID)) { return false; } _s._wD(fN + 'Muting "' + sID + '"'); return _s.sounds[sID].mute(); } return true; }; this.muteAll = function () { _s.mute(); }; this.unmute = function (sID) { var fN = "soundManager.unmute(): ", i; if (typeof sID !== "string") { sID = null; } if (!sID) { _s._wD(fN + "Unmuting all sounds"); for (i = _s.soundIDs.length; i--; ) { _s.sounds[_s.soundIDs[i]].unmute(); } _s.muted = false; } else { if (!_idCheck(sID)) { return false; } _s._wD(fN + 'Unmuting "' + sID + '"'); return _s.sounds[sID].unmute(); } return true; }; this.unmuteAll = function () { _s.unmute(); }; this.toggleMute = function (sID) { if (!_idCheck(sID)) { return false; } return _s.sounds[sID].toggleMute(); }; this.getMemoryUse = function () { if (_fV === 8) { return 0; } if (_s.o) { return parseInt(_s.o._getMemoryUse(), 10); } }; this.disable = function (bNoDisable) { if (typeof bNoDisable === "undefined") { bNoDisable = false; } if (_disabled) { return false; } _disabled = true; _wDS("shutdown", 1); for (var i = _s.soundIDs.length; i--; ) { _disableObject(_s.sounds[_s.soundIDs[i]]); } _initComplete(bNoDisable); _event.remove(_win, "load", _initUserOnload); return true; }; this.canPlayMIME = function (sMIME) { var result; if (_s.hasHTML5) { result = _html5CanPlay({ type: sMIME }); } if (!_needsFlash || result) { return result; } else { return (sMIME ? (sMIME.match(_s.mimePattern) ? true : false) : null); } }; this.canPlayURL = function (sURL) { var result; if (_s.hasHTML5) { result = _html5CanPlay(sURL); } if (!_needsFlash || result) { return result; } else { return (sURL ? (sURL.match(_s.filePattern) ? true : false) : null); } }; this.canPlayLink = function (oLink) { if (typeof oLink.type !== "undefined" && oLink.type) { if (_s.canPlayMIME(oLink.type)) { return true; } } return _s.canPlayURL(oLink.href); }; this.getSoundById = function (sID, suppressDebug) { if (!sID) { throw new Error("SoundManager.getSoundById(): sID is null/undefined"); } var result = _s.sounds[sID]; if (!result && !suppressDebug) { _s._wD('"' + sID + '" is an invalid sound ID.', 2); } return result; }; this.onready = function (oMethod, oScope) { var sType = "onready"; if (oMethod && oMethod instanceof Function) { if (_didInit) { _wDS("queue", sType); } if (!oScope) { oScope = _win; } _addOnEvent(sType, oMethod, oScope); _processOnEvents(); return true; } else { throw _str("needFunction", sType); } }; this.ontimeout = function (oMethod, oScope) { var sType = "ontimeout"; if (oMethod && oMethod instanceof Function) { if (_didInit) { _wDS("queue"); } if (!oScope) { oScope = _win; } _addOnEvent(sType, oMethod, oScope); _processOnEvents({ type: sType }); return true; } else { throw _str("needFunction", sType); } }; this.getMoviePercent = function () { return (_s.o && typeof _s.o.PercentLoaded !== "undefined" ? _s.o.PercentLoaded() : null); }; this._writeDebug = function (sText, sType, bTimestamp) { if (_s.ondebuglog) { _s.ondebuglog(sText, sType, bTimestamp); } var sDID = "soundmanager-debug", o, oItem, sMethod; if (!_s.debugMode) { return false; } if (typeof bTimestamp !== "undefined" && bTimestamp) { sText = sText + " | " + new Date().getTime(); } if (_hasConsole && _s.useConsole) { sMethod = _debugLevels[sType]; if (typeof console[sMethod] !== "undefined") { console[sMethod](sText); } else { console.log(sText); } if (_s.useConsoleOnly) { return true; } } try { o = _id(sDID); if (!o) { return false; } oItem = _doc.createElement("div"); if (++_wdCount % 2 === 0) { oItem.className = "sm2-alt"; } if (typeof sType === "undefined") { sType = 0; } else { sType = parseInt(sType, 10); } oItem.appendChild(_doc.createTextNode(sText)); if (sType) { if (sType >= 2) { oItem.style.fontWeight = "bold"; } if (sType === 3) { oItem.style.color = "#ff3333"; } } o.insertBefore(oItem, o.firstChild); } catch (e) { } o = null; return true; }; this._wD = this._writeDebug; this._debug = function () { _wDS("currentObj", 1); for (var i = 0, j = _s.soundIDs.length; i < j; i++) { _s.sounds[_s.soundIDs[i]]._debug(); } }; this.reboot = function () { _s._wD("soundManager.reboot()"); if (_s.soundIDs.length) { _s._wD("Destroying " + _s.soundIDs.length + " SMSound objects..."); } var i, j; for (i = _s.soundIDs.length; i--; ) { _s.sounds[_s.soundIDs[i]].destruct(); } try { if (_isIE) { _oRemovedHTML = _s.o.innerHTML; } _oRemoved = _s.o.parentNode.removeChild(_s.o); _s._wD("Flash movie removed."); } catch (e) { _wDS("badRemove", 2); } _oRemovedHTML = _oRemoved = null; _s.enabled = _didInit = _waitingForEI = _initPending = _didAppend = _appendSuccess = _disabled = _s.swfLoaded = false; _s.soundIDs = _s.sounds = []; _s.o = null; for (i in _on_queue) { if (_on_queue.hasOwnProperty(i)) { for (j = _on_queue[i].length; j--; ) { _on_queue[i][j].fired = false; } } } _s._wD(_sm + ": Rebooting..."); _win.setTimeout(function () { _s.beginDelayedInit(); }, 20); }; this.destruct = function () { _s._wD("soundManager.destruct()"); _s.disable(true); }; this.beginDelayedInit = function () { _windowLoaded = true; _dcLoaded(); setTimeout(_beginInit, 20); _delayWaitForEI(); }; SMSound = function (oOptions) { var _t = this, _resetProperties, _add_html5_events, _html5_events, _stop_html5_timer, _start_html5_timer, _get_html5_duration, _a; this.sID = oOptions.id; this.url = oOptions.url; this.options = _mixin(oOptions); this.instanceOptions = this.options; this._iO = this.instanceOptions; this.pan = this.options.pan; this.volume = this.options.volume; this._lastURL = null; this.isHTML5 = false; this.id3 = {}; this._debug = function () { if (_s.debugMode) { var stuff = null, msg = [], sF, sfBracket, maxLength = 64; for (stuff in _t.options) { if (_t.options[stuff] !== null) { if (_t.options[stuff] instanceof Function) { sF = _t.options[stuff].toString(); sF = sF.replace(/\s\s+/g, " "); sfBracket = sF.indexOf("{"); msg.push(" " + stuff + ": {" + sF.substr(sfBracket + 1, (Math.min(Math.max(sF.indexOf("\n") - 1, maxLength), maxLength))).replace(/\n/g, "") + "... }"); } else { msg.push(" " + stuff + ": " + _t.options[stuff]); } } } _s._wD("SMSound() merged options: {\n" + msg.join(", \n") + "\n}"); } }; this._debug(); this.load = function (oOptions) { var oS = null; if (typeof oOptions !== "undefined") { _t._iO = _mixin(oOptions); _t.instanceOptions = _t._iO; } else { oOptions = _t.options; _t._iO = oOptions; _t.instanceOptions = _t._iO; if (_t._lastURL && _t._lastURL !== _t.url) { _wDS("manURL"); _t._iO.url = _t.url; _t.url = null; } } _s._wD("soundManager.load(): " + _t._iO.url, 1); if (_t._iO.url === _t.url && _t.readyState !== 0 && _t.readyState !== 2) { _wDS("onURL", 1); return _t; } _t._lastURL = _t.url; _t.loaded = false; _t.readyState = 1; _t.playState = 0; if (_html5OK(_t._iO)) { _s._wD("HTML5 load: " + _t._iO.url); oS = _t._setup_html5(_t._iO); oS.load(); if (_t._iO.autoPlay) { _t.play(); } } else { try { _t.isHTML5 = false; _t._iO = _policyFix(_loopFix(_t._iO)); if (_fV === 8) { _s.o._load(_t.sID, _t._iO.url, _t._iO.stream, _t._iO.autoPlay, (_t._iO.whileloading ? 1 : 0), _t._iO.loops || 1, _t._iO.usePolicyFile); } else { _s.o._load(_t.sID, _t._iO.url, _t._iO.stream ? true : false, _t._iO.autoPlay ? true : false, _t._iO.loops || 1, _t._iO.autoLoad ? true : false, _t._iO.usePolicyFile); } } catch (e) { _wDS("smError", 2); _debugTS("onload", false); _die(); } } return _t; }; this.unload = function () { if (_t.readyState !== 0) { _s._wD('SMSound.unload(): "' + _t.sID + '"'); if (!_t.isHTML5) { if (_fV === 8) { _s.o._unload(_t.sID, _s.nullURL); } else { _s.o._unload(_t.sID); } } else { _stop_html5_timer(); if (_a) { _a.pause(); _a.src = ""; } } _resetProperties(); } return _t; }; this.destruct = function (_bFromSM) { _s._wD('SMSound.destruct(): "' + _t.sID + '"'); if (!_t.isHTML5) { _t._iO.onfailure = null; _s.o._destroySound(_t.sID); } else { _stop_html5_timer(); if (_a) { _a.pause(); _a.src = "about:blank"; _a.load(); _t._audio = null; _a = null; } } if (!_bFromSM) { _s.destroySound(_t.sID, true); } }; this.play = function (oOptions, _updatePlayState) { var fN = "SMSound.play(): ", allowMulti; _updatePlayState = (typeof _updatePlayState === "undefined" ? true : _updatePlayState); if (!oOptions) { oOptions = {}; } _t._iO = _mixin(oOptions, _t._iO); _t._iO = _mixin(_t._iO, _t.options); _t.instanceOptions = _t._iO; if (_t._iO.serverURL) { if (!_t.connected) { if (!_t.getAutoPlay()) { _s._wD(fN + " Netstream not connected yet - setting autoPlay"); _t.setAutoPlay(true); } return _t; } } if (_html5OK(_t._iO)) { _t._setup_html5(_t._iO); _start_html5_timer(); } if (_t.playState === 1 && !_t.paused) { allowMulti = _t._iO.multiShot; if (!allowMulti) { _s._wD(fN + '"' + _t.sID + '" already playing (one-shot)', 1); return _t; } else { _s._wD(fN + '"' + _t.sID + '" already playing (multi-shot)', 1); if (_t.isHTML5) { _t.setPosition(_t._iO.position); } } } if (!_t.loaded) { if (_t.readyState === 0) { _s._wD(fN + 'Attempting to load "' + _t.sID + '"', 1); if (!_t.isHTML5) { if (!_t._iO.serverURL) { _t._iO.autoPlay = true; _t.load(_t._iO); } } else { _t.load(_t._iO); _t.readyState = 1; } } else { if (_t.readyState === 2) { _s._wD(fN + 'Could not load "' + _t.sID + '" - exiting', 2); return _t; } else { _s._wD(fN + '"' + _t.sID + '" is loading - attempting to play..', 1); } } } else { _s._wD(fN + '"' + _t.sID + '"'); } if (_t.paused && _t.position && _t.position > 0) { _s._wD(fN + '"' + _t.sID + '" is resuming from paused state', 1); _t.resume(); } else { _s._wD(fN + '"' + _t.sID + '" is starting to play'); _t.playState = 1; _t.paused = false; if (!_t.instanceCount || _t._iO.multiShotEvents || (_fV > 8 && !_t.isHTML5 && !_t.getAutoPlay())) { _t.instanceCount++; } _t.position = (typeof _t._iO.position !== "undefined" && !isNaN(_t._iO.position) ? _t._iO.position : 0); if (!_t.isHTML5) { _t._iO = _policyFix(_loopFix(_t._iO)); } if (_t._iO.onplay && _updatePlayState) { _t._iO.onplay.apply(_t); _t._onplay_called = true; } _t.setVolume(_t._iO.volume, true); _t.setPan(_t._iO.pan, true); if (!_t.isHTML5) { _s.o._start(_t.sID, _t._iO.loops || 1, (_fV === 9 ? _t.position : _t.position / 1000)); } else { _start_html5_timer(); _t._setup_html5().play(); } } return _t; }; this.start = this.play; this.stop = function (bAll) { if (_t.playState === 1) { _t._onbufferchange(0); _t.resetOnPosition(0); if (!_t.isHTML5) { _t.playState = 0; } _t.paused = false; if (_t._iO.onstop) { _t._iO.onstop.apply(_t); } if (!_t.isHTML5) { _s.o._stop(_t.sID, bAll); if (_t._iO.serverURL) { _t.unload(); } } else { if (_a) { _t.setPosition(0); _a.pause(); _t.playState = 0; _t._onTimer(); _stop_html5_timer(); _t.unload(); } } _t.instanceCount = 0; _t._iO = {}; } return _t; }; this.setAutoPlay = function (autoPlay) { _s._wD("sound " + _t.sID + " turned autoplay " + (autoPlay ? "on" : "off")); _t._iO.autoPlay = autoPlay; _s.o._setAutoPlay(_t.sID, autoPlay); if (autoPlay) { if (!_t.instanceCount && _t.readyState === 1) { _t.instanceCount++; _s._wD("sound " + _t.sID + " incremented instance count to " + _t.instanceCount); } } }; this.getAutoPlay = function () { return _t._iO.autoPlay; }; this.setPosition = function (nMsecOffset, bNoDebug) { if (nMsecOffset === undefined) { nMsecOffset = 0; } var position, offset = (_t.isHTML5 ? Math.max(nMsecOffset, 0) : Math.min(_t.duration || _t._iO.duration, Math.max(nMsecOffset, 0))); _t.position = offset; _t.resetOnPosition(_t.position); _t._iO.position = offset; if (!_t.isHTML5) { position = _fV === 9 ? _t.position : _t.position / 1000; if (_t.serverURL && _t.playState === 0) { _t.play({ position: position }); } else { _s.o._setPosition(_t.sID, position, (_t.paused || !_t.playState)); } } else { if (_a) { _s._wD("setPosition(): setting position to " + (_t.position / 1000)); if (_t.playState) { try { _a.currentTime = _t.position / 1000; } catch (e) { _s._wD("setPosition(" + _t.position + "): WARN: Caught exception: " + e.message, 2); } } else { _s._wD("HTML5 warning: cannot set position while playState == 0 (not playing)", 2); } if (_t.paused) { _t._onTimer(true); if (_t._iO.useMovieStar) { _t.resume(); } } } } return _t; }; this.pause = function (bCallFlash) { if (_t.paused || (_t.playState === 0 && _t.readyState !== 1)) { return _t; } _s._wD("SMSound.pause()"); _t.paused = true; if (!_t.isHTML5) { if (bCallFlash || bCallFlash === undefined) { _s.o._pause(_t.sID); } } else { _t._setup_html5().pause(); _stop_html5_timer(); } if (_t._iO.onpause) { _t._iO.onpause.apply(_t); } return _t; }; this.resume = function () { if (!_t.paused) { return _t; } _s._wD("SMSound.resume()"); _t.paused = false; _t.playState = 1; if (!_t.isHTML5) { _s.o._pause(_t.sID); if (_t._iO.isMovieStar && _isWebkit) { _t.setPosition(_t.position); } } else { _t._setup_html5().play(); _start_html5_timer(); } if (!_t._onplay_called && _t._iO.onplay) { _t._iO.onplay.apply(_t); _t._onplay_called = true; } else { if (_t._iO.onresume) { _t._iO.onresume.apply(_t); } } return _t; }; this.togglePause = function () { _s._wD("SMSound.togglePause()"); if (_t.playState === 0) { _t.play({ position: (_fV === 9 && !_t.isHTML5 ? _t.position : _t.position / 1000) }); return _t; } if (_t.paused) { _t.resume(); } else { _t.pause(); } return _t; }; this.setPan = function (nPan, bInstanceOnly) { if (typeof nPan === "undefined") { nPan = 0; } if (typeof bInstanceOnly === "undefined") { bInstanceOnly = false; } if (!_t.isHTML5) { _s.o._setPan(_t.sID, nPan); } _t._iO.pan = nPan; if (!bInstanceOnly) { _t.pan = nPan; } return _t; }; this.setVolume = function (nVol, bInstanceOnly) { if (typeof nVol === "undefined") { nVol = 100; } if (typeof bInstanceOnly === "undefined") { bInstanceOnly = false; } if (!_t.isHTML5) { _s.o._setVolume(_t.sID, (_s.muted && !_t.muted) || _t.muted ? 0 : nVol); } else { if (_a) { _a.volume = nVol / 100; } } _t._iO.volume = nVol; if (!bInstanceOnly) { _t.volume = nVol; } return _t; }; this.mute = function () { _t.muted = true; if (!_t.isHTML5) { _s.o._setVolume(_t.sID, 0); } else { if (_a) { _a.muted = true; } } return _t; }; this.unmute = function () { _t.muted = false; var hasIO = typeof _t._iO.volume !== "undefined"; if (!_t.isHTML5) { _s.o._setVolume(_t.sID, hasIO ? _t._iO.volume : _t.options.volume); } else { if (_a) { _a.muted = false; } } return _t; }; this.toggleMute = function () { return (_t.muted ? _t.unmute() : _t.mute()); }; this.onposition = function (nPosition, oMethod, oScope) { _t._onPositionItems.push({ position: nPosition, method: oMethod, scope: (typeof oScope !== "undefined" ? oScope : _t), fired: false }); return _t; }; this.processOnPosition = function () { var i, item, j = _t._onPositionItems.length; if (!j || !_t.playState || _t._onPositionFired >= j) { return false; } for (i = j; i--; ) { item = _t._onPositionItems[i]; if (!item.fired && _t.position >= item.position) { item.method.apply(item.scope, [item.position]); item.fired = true; _s._onPositionFired++; } } return true; }; this.resetOnPosition = function (nPosition) { var i, item, j = _t._onPositionItems.length; if (!j) { return false; } for (i = j; i--; ) { item = _t._onPositionItems[i]; if (item.fired && nPosition <= item.position) { item.fired = false; _s._onPositionFired--; } } return true; }; this._onTimer = function (bForce) { var time, x = {}; if (_t._hasTimer || bForce) { if (_a && (bForce || ((_t.playState > 0 || _t.readyState === 1) && !_t.paused))) { _t.duration = _get_html5_duration(); _t.durationEstimate = _t.duration; time = _a.currentTime ? _a.currentTime * 1000 : 0; _t._whileplaying(time, x, x, x, x); return true; } else { _s._wD('_onTimer: Warn for "' + _t.sID + '": ' + (!_a ? "Could not find element. " : "") + (_t.playState === 0 ? "playState bad, 0?" : "playState = " + _t.playState + ", OK")); return false; } } }; _get_html5_duration = function () { var d = (_a ? _a.duration * 1000 : undefined); return (d && !isNaN(d) ? d : null); }; _start_html5_timer = function () { if (_t.isHTML5) { _startTimer(_t); } }; _stop_html5_timer = function () { if (_t.isHTML5) { _stopTimer(_t); } }; _resetProperties = function (bLoaded) { _t._onPositionItems = []; _t._onPositionFired = 0; _t._hasTimer = null; _t._added_events = null; _t._onplay_called = false; _t._audio = null; _a = null; _t.bytesLoaded = null; _t.bytesTotal = null; _t.position = null; _t.duration = (_t._iO && _t._iO.duration ? _t._iO.duration : null); _t.durationEstimate = null; _t.failures = 0; _t.loaded = false; _t.playState = 0; _t.paused = false; _t.readyState = 0; _t.muted = false; _t.didBeforeFinish = false; _t.didJustBeforeFinish = false; _t.isBuffering = false; _t.instanceOptions = {}; _t.instanceCount = 0; _t.peakData = { left: 0, right: 0 }; _t.waveformData = { left: [], right: [] }; _t.eqData = []; _t.eqData.left = []; _t.eqData.right = []; }; _resetProperties(); this._setup_html5 = function (oOptions) { var _iO = _mixin(_t._iO, oOptions); if (_a) { if (_t.url !== _iO.url) { _s._wD("setting new URL on existing object: " + _iO.url); _a.src = _iO.url; } } else { _s._wD("creating HTML5 Audio() element with URL: " + _iO.url); _t._audio = new Audio(_iO.url); _a = _t._audio; _t.isHTML5 = true; _add_html5_events(); } _a.loop = (_iO.loops > 1 ? "loop" : ""); return _t._audio; }; _html5_events = { canplay: function (e) { _s._wD("HTML5::canplay: " + _t.sID); _t._onbufferchange(0); }, load: function (e) { if (_a && !_t.loaded) { _t._onbufferchange(0); _t._whileloading(_t.bytesTotal, _t.bytesTotal, _get_html5_duration()); _t._onload(true); } }, ended: function (e) { _s._wD("HTML5::ended: " + _t.sID); _t._onfinish(); }, error: function (e) { if (_a) { _s._wD("HTML5::error: " + _a.error.code); _t._onload(false); } }, loadstart: function (e) { _s._wD("HTML5::loadstart: " + _t.sID); _t._onbufferchange(1); }, play: function (e) { _s._wD("HTML5::play: " + _t.sID); _t._onbufferchange(0); }, playing: function (e) { _s._wD("HTML5::playing: " + _t.sID); _t._onbufferchange(0); }, progress: function (e) { if (!_a || _t.loaded) { return false; } var i, j, str, loadSum = 0, buffered = 0, isProgress = (e.type === "progress"), ranges = e.target.buffered, loaded = (e.loaded || 0), total = (e.total || 1); if (ranges && ranges.length) { for (i = ranges.length; i--; ) { buffered = (ranges.end(i) - ranges.start(i)); } loaded = buffered / e.target.duration; if (isProgress && ranges.length > 1) { str = []; j = ranges.length; for (i = 0; i < j; i++) { str.push(e.target.buffered.start(i) + "-" + e.target.buffered.end(i)); } _s._wD("HTML5::progress: timeRanges: " + str.join(", ")); } if (isProgress) { _s._wD("HTML5::progress: " + _t.sID + ": " + Math.floor(loaded * 100) + "% loaded"); } } _t._onbufferchange(0); _t._whileloading(loaded, total, _get_html5_duration()); if (loaded && total && loaded === total) { _html5_events.load(); } }, suspend: function (e) { _s._wD("HTML5::suspend: " + _t.sID); _html5_events.progress(e); }, timeupdate: function (e) { _t._onTimer(); }, waiting: function (e) { _s._wD("HTML5::waiting: " + _t.sID); _t._onbufferchange(1); } }; _add_html5_events = function () { if (_t._added_events) { return false; } var f; function add(oEvt, oFn, bCapture) { return (_a ? _a.addEventListener(oEvt, oFn, bCapture || false) : null); } _t._added_events = true; for (f in _html5_events) { if (_html5_events.hasOwnProperty(f)) { add(f, _html5_events[f]); } } return true; }; this._whileloading = function (nBytesLoaded, nBytesTotal, nDuration, nBufferLength) { _t.bytesLoaded = nBytesLoaded; _t.bytesTotal = nBytesTotal; _t.duration = Math.floor(nDuration); _t.bufferLength = nBufferLength; if (!_t._iO.isMovieStar) { if (_t._iO.duration) { _t.durationEstimate = (_t.duration > _t._iO.duration) ? _t.duration : _t._iO.duration; } else { _t.durationEstimate = parseInt((_t.bytesTotal / _t.bytesLoaded) * _t.duration, 10); } if (_t.durationEstimate === undefined) { _t.durationEstimate = _t.duration; } if (_t.readyState !== 3 && _t._iO.whileloading) { _t._iO.whileloading.apply(_t); } } else { _t.durationEstimate = _t.duration; if (_t.readyState !== 3 && _t._iO.whileloading) { _t._iO.whileloading.apply(_t); } } }; this._onid3 = function (oID3PropNames, oID3Data) { _s._wD('SMSound._onid3(): "' + this.sID + '" ID3 data received.'); var oData = [], i, j; for (i = 0, j = oID3PropNames.length; i < j; i++) { oData[oID3PropNames[i]] = oID3Data[i]; } _t.id3 = _mixin(_t.id3, oData); if (_t._iO.onid3) { _t._iO.onid3.apply(_t); } }; this._whileplaying = function (nPosition, oPeakData, oWaveformDataLeft, oWaveformDataRight, oEQData) { if (isNaN(nPosition) || nPosition === null) { return false; } if (_t.playState === 0 && nPosition > 0) { nPosition = 0; } _t.position = nPosition; _t.processOnPosition(); if (_fV > 8 && !_t.isHTML5) { if (_t._iO.usePeakData && typeof oPeakData !== "undefined" && oPeakData) { _t.peakData = { left: oPeakData.leftPeak, right: oPeakData.rightPeak }; } if (_t._iO.useWaveformData && typeof oWaveformDataLeft !== "undefined" && oWaveformDataLeft) { _t.waveformData = { left: oWaveformDataLeft.split(","), right: oWaveformDataRight.split(",") }; } if (_t._iO.useEQData) { if (typeof oEQData !== "undefined" && oEQData && oEQData.leftEQ) { var eqLeft = oEQData.leftEQ.split(","); _t.eqData = eqLeft; _t.eqData.left = eqLeft; if (typeof oEQData.rightEQ !== "undefined" && oEQData.rightEQ) { _t.eqData.right = oEQData.rightEQ.split(","); } } } } if (_t.playState === 1) { if (!_t.isHTML5 && _s.flashVersion === 8 && !_t.position && _t.isBuffering) { _t._onbufferchange(0); } if (_t._iO.whileplaying) { _t._iO.whileplaying.apply(_t); } if ((_t.loaded || (!_t.loaded && _t._iO.isMovieStar)) && _t._iO.onbeforefinish && _t._iO.onbeforefinishtime && !_t.didBeforeFinish && _t.duration - _t.position <= _t._iO.onbeforefinishtime) { _t._onbeforefinish(); } } return true; }; this._onconnect = function (bSuccess) { var fN = "SMSound._onconnect(): "; bSuccess = (bSuccess === 1); _s._wD(fN + '"' + _t.sID + '"' + (bSuccess ? " connected." : " failed to connect? - " + _t.url), (bSuccess ? 1 : 2)); _t.connected = bSuccess; if (bSuccess) { _t.failures = 0; if (_t._iO.onconnect) { _t._iO.onconnect.apply(_t, [bSuccess]); } if (_idCheck(_t.sID) && (_t.options.autoLoad || _t.getAutoPlay())) { _t.play(undefined, _t.getAutoPlay()); } } }; this._onload = function (nSuccess) { var fN = "SMSound._onload(): ", loadOK = (nSuccess ? true : false); _s._wD(fN + '"' + _t.sID + '"' + (loadOK ? " loaded." : " failed to load? - " + _t.url), (loadOK ? 1 : 2)); if (!loadOK && !_t.isHTML5) { if (_s.sandbox.noRemote === true) { _s._wD(fN + _str("noNet"), 1); } if (_s.sandbox.noLocal === true) { _s._wD(fN + _str("noLocal"), 1); } } _t.loaded = loadOK; _t.readyState = loadOK ? 3 : 2; _t._onbufferchange(0); if (_t._iO.onload) { _t._iO.onload.apply(_t, [loadOK]); } return true; }; this._onfailure = function (msg, level, code) { _t.failures++; _s._wD('SMSound._onfailure(): "' + _t.sID + '" count ' + _t.failures); if (_t._iO.onfailure && _t.failures === 1) { _t._iO.onfailure(_t, msg, level, code); } else { _s._wD("SMSound._onfailure(): ignoring"); } }; this._onbeforefinish = function () { if (!_t.didBeforeFinish) { _t.didBeforeFinish = true; if (_t._iO.onbeforefinish) { _s._wD('SMSound._onbeforefinish(): "' + _t.sID + '"'); _t._iO.onbeforefinish.apply(_t); } } }; this._onjustbeforefinish = function (msOffset) { if (!_t.didJustBeforeFinish) { _t.didJustBeforeFinish = true; if (_t._iO.onjustbeforefinish) { _s._wD('SMSound._onjustbeforefinish(): "' + _t.sID + '"'); _t._iO.onjustbeforefinish.apply(_t); } } }; this._onstats = function (stats) { if (_t._iO.onstats) { _t._iO.onstats(_t, stats); } }; this._onfinish = function () { _t._onbufferchange(0); _t.resetOnPosition(0); if (_t._iO.onbeforefinishcomplete) { _t._iO.onbeforefinishcomplete.apply(_t); } _t.didBeforeFinish = false; _t.didJustBeforeFinish = false; if (_t.instanceCount) { _t.instanceCount--; if (!_t.instanceCount) { _t.playState = 0; _t.paused = false; _t.instanceCount = 0; _t.instanceOptions = {}; _stop_html5_timer(); } if (!_t.instanceCount || _t._iO.multiShotEvents) { if (_t._iO.onfinish) { _s._wD('SMSound._onfinish(): "' + _t.sID + '"'); _t._iO.onfinish.apply(_t); } } } }; this._onbufferchange = function (nIsBuffering) { var fN = "SMSound._onbufferchange()"; if (_t.playState === 0) { return false; } if ((nIsBuffering && _t.isBuffering) || (!nIsBuffering && !_t.isBuffering)) { return false; } _t.isBuffering = (nIsBuffering === 1); if (_t._iO.onbufferchange) { _s._wD(fN + ": " + nIsBuffering); _t._iO.onbufferchange.apply(_t); } return true; }; this._ondataerror = function (sError) { if (_t.playState > 0) { _s._wD("SMSound._ondataerror(): " + sError); if (_t._iO.ondataerror) { _t._iO.ondataerror.apply(_t); } } }; }; _getDocument = function () { return (_doc.body ? _doc.body : (_doc._docElement ? _doc.documentElement : _doc.getElementsByTagName("div")[0])); }; _id = function (sID) { return _doc.getElementById(sID); }; _mixin = function (oMain, oAdd) { var o1 = {}, i, o2, o; for (i in oMain) { if (oMain.hasOwnProperty(i)) { o1[i] = oMain[i]; } } o2 = (typeof oAdd === "undefined" ? _s.defaultOptions : oAdd); for (o in o2) { if (o2.hasOwnProperty(o) && typeof o1[o] === "undefined") { o1[o] = o2[o]; } } return o1; }; _event = (function () { var old = (_win.attachEvent), evt = { add: (old ? "attachEvent" : "addEventListener"), remove: (old ? "detachEvent" : "removeEventListener") }; function getArgs(oArgs) { var args = _slice.call(oArgs), len = args.length; if (old) { args[1] = "on" + args[1]; if (len > 3) { args.pop(); } } else { if (len === 3) { args.push(false); } } return args; } function apply(args, sType) { var element = args.shift(), method = [evt[sType]]; if (old) { element[method](args[0], args[1]); } else { element[method].apply(element, args); } } function add() { apply(getArgs(arguments), "add"); } function remove() { apply(getArgs(arguments), "remove"); } return { add: add, remove: remove }; } ()); _html5OK = function (iO) { return (iO.type ? _html5CanPlay({ type: iO.type }) : _html5CanPlay(iO.url) || _html5Only); }; _html5CanPlay = function (sURL) { if (!_s.useHTML5Audio || !_s.hasHTML5) { return false; } var result, mime, fileExt, item, aF = _s.audioFormats; if (!_html5Ext) { _html5Ext = []; for (item in aF) { if (aF.hasOwnProperty(item)) { _html5Ext.push(item); if (aF[item].related) { _html5Ext = _html5Ext.concat(aF[item].related); } } } _html5Ext = new RegExp("\\.(" + _html5Ext.join("|") + ")", "i"); } mime = (typeof sURL.type !== "undefined" ? sURL.type : null); fileExt = (typeof sURL === "string" ? sURL.toLowerCase().match(_html5Ext) : null); if (!fileExt || !fileExt.length) { if (!mime) { return false; } } else { fileExt = fileExt[0].substr(1); } if (fileExt && typeof _s.html5[fileExt] !== "undefined") { return _s.html5[fileExt]; } else { if (!mime) { if (fileExt && _s.html5[fileExt]) { return _s.html5[fileExt]; } else { mime = "audio/" + fileExt; } } result = _s.html5.canPlayType(mime); _s.html5[fileExt] = result; return result; } }; _testHTML5 = function () { if (!_s.useHTML5Audio || typeof Audio === "undefined") { return false; } var a = (typeof Audio !== "undefined" ? new Audio() : null), item, support = {}, aF, i; function _cp(m) { var canPlay, i, j, isOK = false; if (!a || typeof a.canPlayType !== "function") { return false; } if (m instanceof Array) { for (i = 0, j = m.length; i < j && !isOK; i++) { if (_s.html5[m[i]] || a.canPlayType(m[i]).match(_s.html5Test)) { isOK = true; _s.html5[m[i]] = true; } } return isOK; } else { canPlay = (a && typeof a.canPlayType === "function" ? a.canPlayType(m) : false); return (canPlay && (canPlay.match(_s.html5Test) ? true : false)); } } aF = _s.audioFormats; for (item in aF) { if (aF.hasOwnProperty(item)) { support[item] = _cp(aF[item].type); if (aF[item] && aF[item].related) { for (i = 0; i < aF[item].related.length; i++) { _s.html5[aF[item].related[i]] = support[item]; } } } } support.canPlayType = (a ? _cp : null); _s.html5 = _mixin(_s.html5, support); return true; }; _strings = { notReady: "Not loaded yet - wait for soundManager.onload()/onready()", notOK: "Audio support is not available.", appXHTML: _sm + "::createMovie(): appendChild/innerHTML set failed. May be app/xhtml+xml DOM-related.", spcWmode: _sm + "::createMovie(): Removing wmode, preventing win32 below-the-fold SWF loading issue", swf404: _sm + ": Verify that %s is a valid path.", tryDebug: "Try " + _sm + ".debugFlash = true for more security details (output goes to SWF.)", checkSWF: "See SWF output for more debug info.", localFail: _sm + ": Non-HTTP page (" + _doc.location.protocol + " URL?) Review Flash player security settings for this special case:\nhttp://www.macromedia.com/support/documentation/en/flashplayer/help/settings_manager04.html\nMay need to add/allow path, eg. c:/sm2/ or /users/me/sm2/", waitFocus: _sm + ": Special case: Waiting for focus-related event..", waitImpatient: _sm + ": Getting impatient, still waiting for Flash%s...", waitForever: _sm + ": Waiting indefinitely for Flash (will recover if unblocked)...", needFunction: _sm + ": Function object expected for %s", badID: 'Warning: Sound ID "%s" should be a string, starting with a non-numeric character', noMS: "MovieStar mode not enabled. Exiting.", currentObj: "--- " + _sm + "._debug(): Current sound objects ---", waitEI: _sm + "::initMovie(): Waiting for ExternalInterface call from Flash..", waitOnload: _sm + ": Waiting for window.onload()", docLoaded: _sm + ": Document already loaded", onload: _sm + "::initComplete(): calling soundManager.onload()", onloadOK: _sm + ".onload() complete", init: "-- " + _sm + "::init() --", didInit: _sm + "::init(): Already called?", flashJS: _sm + ": Attempting to call Flash from JS..", noPolling: _sm + ": Polling (whileloading()/whileplaying() support) is disabled.", secNote: "Flash security note: Network/internet URLs will not load due to security restrictions. Access can be configured via Flash Player Global Security Settings Page: http://www.macromedia.com/support/documentation/en/flashplayer/help/settings_manager04.html", badRemove: "Warning: Failed to remove flash movie.", noPeak: "Warning: peakData features unsupported for movieStar formats", shutdown: _sm + ".disable(): Shutting down", queue: _sm + ": Queueing %s handler", smFail: _sm + ": Failed to initialise.", smError: "SMSound.load(): Exception: JS-Flash communication failed, or JS error.", fbTimeout: "No flash response, applying ." + _s.swfCSS.swfTimedout + " CSS..", fbLoaded: "Flash loaded", fbHandler: "soundManager::flashBlockHandler()", manURL: "SMSound.load(): Using manually-assigned URL", onURL: _sm + ".load(): current URL already assigned.", badFV: 'soundManager.flashVersion must be 8 or 9. "%s" is invalid. Reverting to %s.', as2loop: "Note: Setting stream:false so looping can work (flash 8 limitation)", noNSLoop: "Note: Looping not implemented for MovieStar formats", needfl9: "Note: Switching to flash 9, required for MP4 formats.", mfTimeout: "Setting flashLoadTimeout = 0 (infinite) for off-screen, mobile flash case", mfOn: "mobileFlash::enabling on-screen flash repositioning", policy: "Enabling usePolicyFile for data access" }; _str = function () { var args = _slice.call(arguments), o = args.shift(), str = (_strings && _strings[o] ? _strings[o] : ""), i, j; if (str && args && args.length) { for (i = 0, j = args.length; i < j; i++) { str = str.replace("%s", args[i]); } } return str; }; _loopFix = function (sOpt) { if (_fV === 8 && sOpt.loops > 1 && sOpt.stream) { _wDS("as2loop"); sOpt.stream = false; } return sOpt; }; _policyFix = function (sOpt, sPre) { if (sOpt && !sOpt.usePolicyFile && (sOpt.onid3 || sOpt.usePeakData || sOpt.useWaveformData || sOpt.useEQData)) { _s._wD((sPre ? sPre + ":" : "") + _str("policy")); sOpt.usePolicyFile = true; } return sOpt; }; _complain = function (sMsg) { if (typeof console !== "undefined" && typeof console.warn !== "undefined") { console.warn(sMsg); } else { _s._wD(sMsg); } }; _doNothing = function () { return false; }; _disableObject = function (o) { for (var oProp in o) { if (o.hasOwnProperty(oProp) && typeof o[oProp] === "function") { o[oProp] = _doNothing; } } oProp = null; }; _failSafely = function (bNoDisable) { if (typeof bNoDisable === "undefined") { bNoDisable = false; } if (_disabled || bNoDisable) { _wDS("smFail", 2); _s.disable(bNoDisable); } }; _normalizeMovieURL = function (smURL) { var urlParams = null; if (smURL) { if (smURL.match(/\.swf(\?.*)?$/i)) { urlParams = smURL.substr(smURL.toLowerCase().lastIndexOf(".swf?") + 4); if (urlParams) { return smURL; } } else { if (smURL.lastIndexOf("/") !== smURL.length - 1) { smURL = smURL + "/"; } } } return (smURL && smURL.lastIndexOf("/") !== -1 ? smURL.substr(0, smURL.lastIndexOf("/") + 1) : "./") + _s.movieURL; }; _setVersionInfo = function () { if (_fV !== 8 && _fV !== 9) { _s._wD(_str("badFV", _fV, _defaultFlashVersion)); _s.flashVersion = _defaultFlashVersion; } var isDebug = (_s.debugMode || _s.debugFlash ? "_debug.swf" : ".swf"); if (_s.useHTML5Audio && !_html5Only && _s.audioFormats.mp4.required && _s.flashVersion < 9) { _s._wD(_str("needfl9")); _s.flashVersion = 9; } _fV = _s.flashVersion; _s.version = _s.versionNumber + (_html5Only ? " (HTML5-only mode)" : (_fV === 9 ? " (AS3/Flash 9)" : " (AS2/Flash 8)")); if (_fV > 8) { _s.defaultOptions = _mixin(_s.defaultOptions, _s.flash9Options); _s.features.buffering = true; } if (_fV > 8 && _s.useMovieStar) { _s.defaultOptions = _mixin(_s.defaultOptions, _s.movieStarOptions); _s.filePatterns.flash9 = new RegExp("\\.(mp3|" + _s.netStreamTypes.join("|") + ")(\\?.*)?$", "i"); _s.mimePattern = _s.netStreamMimeTypes; _s.features.movieStar = true; } else { _s.useMovieStar = false; _s.features.movieStar = false; } _s.filePattern = _s.filePatterns[(_fV !== 8 ? "flash9" : "flash8")]; _s.movieURL = (_fV === 8 ? "soundmanager2.swf" : "soundmanager2_flash9.swf").replace(".swf", isDebug); _s.features.peakData = _s.features.waveformData = _s.features.eqData = (_fV > 8); }; _setPolling = function (bPolling, bHighPerformance) { if (!_s.o || !_s.allowPolling) { return false; } _s.o._setPolling(bPolling, bHighPerformance); }; function _initDebug() { if (_s.debugURLParam.test(_wl)) { _s.debugMode = true; } if (_id(_s.debugID)) { return false; } var oD, oDebug, oTarget, oToggle, tmp; if (_s.debugMode && !_id(_s.debugID) && ((!_hasConsole || !_s.useConsole) || (_s.useConsole && _hasConsole && !_s.consoleOnly))) { oD = _doc.createElement("div"); oD.id = _s.debugID + "-toggle"; oToggle = { position: "fixed", bottom: "0px", right: "0px", width: "1.2em", height: "1.2em", lineHeight: "1.2em", margin: "2px", textAlign: "center", border: "1px solid #999", cursor: "pointer", background: "#fff", color: "#333", zIndex: 10001 }; oD.appendChild(_doc.createTextNode("-")); oD.onclick = _toggleDebug; oD.title = "Toggle SM2 debug console"; if (_ua.match(/msie 6/i)) { oD.style.position = "absolute"; oD.style.cursor = "hand"; } for (tmp in oToggle) { if (oToggle.hasOwnProperty(tmp)) { oD.style[tmp] = oToggle[tmp]; } } oDebug = _doc.createElement("div"); oDebug.id = _s.debugID; oDebug.style.display = (_s.debugMode ? "block" : "none"); if (_s.debugMode && !_id(oD.id)) { try { oTarget = _getDocument(); oTarget.appendChild(oD); } catch (e2) { throw new Error(_str("appXHTML")); } oTarget.appendChild(oDebug); } } oTarget = null; } _createMovie = function (smID, smURL) { var specialCase = null, remoteURL = (smURL ? smURL : _s.url), localURL = (_s.altURL ? _s.altURL : remoteURL), oEmbed, oMovie, oTarget = _getDocument(), tmp, movieHTML, oEl, extraClass = _getSWFCSS(), s, x, sClass, side = "100%", isRTL = null, html = _doc.getElementsByTagName("html")[0]; isRTL = (html && html.dir && html.dir.match(/rtl/i)); smID = (typeof smID === "undefined" ? _s.id : smID); if (_didAppend && _appendSuccess) { return false; } function _initMsg() { _s._wD("-- SoundManager 2 " + _s.version + (!_html5Only && _s.useHTML5Audio ? (_s.hasHTML5 ? " + HTML5 audio" : ", no HTML5 audio support") : "") + (!_html5Only ? (_s.useMovieStar ? ", MovieStar mode" : "") + (_s.useHighPerformance ? ", high performance mode, " : ", ") + ((_s.flashPollingInterval ? "custom (" + _s.flashPollingInterval + "ms)" : (_s.useFastPolling ? "fast" : "normal")) + " polling") + (_s.wmode ? ", wmode: " + _s.wmode : "") + (_s.debugFlash ? ", flash debug mode" : "") + (_s.useFlashBlock ? ", flashBlock mode" : "") : "") + " --", 1); } if (_html5Only) { _setVersionInfo(); _initMsg(); _s.oMC = _id(_s.movieID); _init(); _didAppend = true; _appendSuccess = true; return false; } _didAppend = true; _setVersionInfo(); _s.url = _normalizeMovieURL(_s._overHTTP ? remoteURL : localURL); smURL = _s.url; _s.wmode = (!_s.wmode && _s.useHighPerformance && !_s.useMovieStar ? "transparent" : _s.wmode); if (_s.wmode !== null && !_isIE && !_s.useHighPerformance && navigator.platform.match(/win32/i)) { _s.specialWmodeCase = true; _wDS("spcWmode"); _s.wmode = null; } oEmbed = { name: smID, id: smID, src: smURL, width: side, height: side, quality: "high", allowScriptAccess: _s.allowScriptAccess, bgcolor: _s.bgColor, pluginspage: "http://www.macromedia.com/go/getflashplayer", type: "application/x-shockwave-flash", wmode: _s.wmode }; if (_s.debugFlash) { oEmbed.FlashVars = "debug=1"; } if (!_s.wmode) { delete oEmbed.wmode; } if (_isIE) { oMovie = _doc.createElement("div"); movieHTML = '<object id="' + smID + '" data="' + smURL + '" type="' + oEmbed.type + '" width="' + oEmbed.width + '" height="' + oEmbed.height + '"><param name="movie" value="' + smURL + '" /><param name="AllowScriptAccess" value="' + _s.allowScriptAccess + '" /><param name="quality" value="' + oEmbed.quality + '" />' + (_s.wmode ? '<param name="wmode" value="' + _s.wmode + '" /> ' : "") + '<param name="bgcolor" value="' + _s.bgColor + '" />' + (_s.debugFlash ? '<param name="FlashVars" value="' + oEmbed.FlashVars + '" />' : "") + "<!-- --></object>"; } else { oMovie = _doc.createElement("embed"); for (tmp in oEmbed) { if (oEmbed.hasOwnProperty(tmp)) { oMovie.setAttribute(tmp, oEmbed[tmp]); } } } _initDebug(); extraClass = _getSWFCSS(); oTarget = _getDocument(); if (oTarget) { _s.oMC = _id(_s.movieID) ? _id(_s.movieID) : _doc.createElement("div"); if (!_s.oMC.id) { _s.oMC.id = _s.movieID; _s.oMC.className = _s.swfCSS.swfDefault + " " + extraClass; s = null; oEl = null; if (!_s.useFlashBlock) { if (_s.useHighPerformance) { s = { position: "fixed", width: "8px", height: "8px", bottom: "0px", left: "0px", overflow: "hidden", hasPriority: "true" }; } else { s = { position: "absolute", width: "6px", height: "6px", top: "-9999px", left: "-9999px", hasPriority: "true" }; if (isRTL) { s.left = Math.abs(parseInt(s.left, 10)) + "px"; } } } if (_isWebkit) { _s.oMC.style.zIndex = 10000; } if (!_s.debugFlash) { for (x in s) { if (s.hasOwnProperty(x)) { _s.oMC.style[x] = s[x]; } } } try { if (!_isIE) { _s.oMC.appendChild(oMovie); } oTarget.appendChild(_s.oMC); if (_isIE) { oEl = _s.oMC.appendChild(_doc.createElement("div")); oEl.className = _s.swfCSS.swfBox; oEl.innerHTML = movieHTML; } _appendSuccess = true; } catch (e) { throw new Error(_str("appXHTML")); } } else { sClass = _s.oMC.className; _s.oMC.className = (sClass ? sClass + " " : _s.swfCSS.swfDefault) + (extraClass ? " " + extraClass : ""); _s.oMC.appendChild(oMovie); if (_isIE) { oEl = _s.oMC.appendChild(_doc.createElement("div")); oEl.className = _s.swfCSS.swfBox; oEl.innerHTML = movieHTML; } _appendSuccess = true; } } if (specialCase) { _s._wD(specialCase); } _initMsg(); _s._wD("soundManager::createMovie(): Trying to load " + smURL + (!_s._overHTTP && _s.altURL ? " (alternate URL)" : ""), 1); return true; }; _idCheck = this.getSoundById; _initMovie = function () { if (_html5Only) { _createMovie(); return false; } if (_s.o) { return false; } _s.o = _s.getMovie(_s.id); if (!_s.o) { if (!_oRemoved) { _createMovie(_s.id, _s.url); } else { if (!_isIE) { _s.oMC.appendChild(_oRemoved); } else { _s.oMC.innerHTML = _oRemovedHTML; } _oRemoved = null; _didAppend = true; } _s.o = _s.getMovie(_s.id); } if (_s.o) { _s._wD("soundManager::initMovie(): Got " + _s.o.nodeName + " element (" + (_didAppend ? "created via JS" : "static HTML") + ")"); _wDS("waitEI"); } if (_s.oninitmovie instanceof Function) { setTimeout(_s.oninitmovie, 1); } return true; }; _go = function (sURL) { if (sURL) { _s.url = sURL; } _initMovie(); }; _delayWaitForEI = function () { setTimeout(_waitForEI, 500); }; _waitForEI = function () { if (_waitingForEI) { return false; } _waitingForEI = true; _event.remove(_win, "load", _delayWaitForEI); if (_tryInitOnFocus && !_isFocused) { _wDS("waitFocus"); return false; } var p; if (!_didInit) { p = _s.getMoviePercent(); _s._wD(_str("waitImpatient", (p === 100 ? " (SWF loaded)" : (p > 0 ? " (SWF " + p + "% loaded)" : "")))); } setTimeout(function () { p = _s.getMoviePercent(); if (!_didInit) { _s._wD(_sm + ": No Flash response within expected time.\nLikely causes: " + (p === 0 ? "Loading " + _s.movieURL + " may have failed (and/or Flash " + _fV + "+ not present?), " : "") + "Flash blocked or JS-Flash security error." + (_s.debugFlash ? " " + _str("checkSWF") : ""), 2); if (!_s._overHTTP && p) { _wDS("localFail", 2); if (!_s.debugFlash) { _wDS("tryDebug", 2); } } if (p === 0) { _s._wD(_str("swf404", _s.url)); } _debugTS("flashtojs", false, ": Timed out" + _s._overHTTP ? " (Check flash security or flash blockers)" : " (No plugin/missing SWF?)"); } if (!_didInit && _okToDisable) { if (p === null) { if (_s.useFlashBlock || _s.flashLoadTimeout === 0) { if (_s.useFlashBlock) { _flashBlockHandler(); } _wDS("waitForever"); } else { _failSafely(true); } } else { if (_s.flashLoadTimeout === 0) { _wDS("waitForever"); } else { _failSafely(true); } } } }, _s.flashLoadTimeout); }; _go = function (sURL) { if (sURL) { _s.url = sURL; } _initMovie(); }; _wDS = function (o, errorLevel) { if (!o) { return ""; } else { return _s._wD(_str(o), errorLevel); } }; if (_wl.indexOf("debug=alert") + 1 && _s.debugMode) { _s._wD = function (sText) { alert(sText); }; } _toggleDebug = function () { var o = _id(_s.debugID), oT = _id(_s.debugID + "-toggle"); if (!o) { return false; } if (_debugOpen) { oT.innerHTML = "+"; o.style.display = "none"; } else { oT.innerHTML = "-"; o.style.display = "block"; } _debugOpen = !_debugOpen; }; _debugTS = function (sEventType, bSuccess, sMessage) { if (typeof sm2Debugger !== "undefined") { try { sm2Debugger.handleEvent(sEventType, bSuccess, sMessage); } catch (e) { } } return true; }; _getSWFCSS = function () { var css = []; if (_s.debugMode) { css.push(_s.swfCSS.sm2Debug); } if (_s.debugFlash) { css.push(_s.swfCSS.flashDebug); } if (_s.useHighPerformance) { css.push(_s.swfCSS.highPerf); } return css.join(" "); }; _flashBlockHandler = function () { var name = _str("fbHandler"), p = _s.getMoviePercent(); if (!_s.ok()) { if (_needsFlash) { _s.oMC.className = _getSWFCSS() + " " + _s.swfCSS.swfDefault + " " + (p === null ? _s.swfCSS.swfTimedout : _s.swfCSS.swfError); _s._wD(name + ": " + _str("fbTimeout") + (p ? " (" + _str("fbLoaded") + ")" : "")); } _s.didFlashBlock = true; _processOnEvents({ type: "ontimeout", ignoreInit: true }); if (_s.onerror instanceof Function) { _s.onerror.apply(_win); } } else { if (_s.didFlashBlock) { _s._wD(name + ": Unblocked"); } if (_s.oMC) { _s.oMC.className = _getSWFCSS() + " " + _s.swfCSS.swfDefault + (" " + _s.swfCSS.swfUnblocked); } } }; _handleFocus = function () { function cleanup() { _event.remove(_win, "focus", _handleFocus); _event.remove(_win, "load", _handleFocus); } if (_isFocused || !_tryInitOnFocus) { cleanup(); return true; } _okToDisable = true; _isFocused = true; _s._wD("soundManager::handleFocus()"); if (_isSafari && _tryInitOnFocus) { _event.remove(_win, "mousemove", _handleFocus); } _waitingForEI = false; cleanup(); return true; }; _initComplete = function (bNoDisable) { if (_didInit) { return false; } if (_html5Only) { _s._wD("-- SoundManager 2: loaded --"); _didInit = true; _processOnEvents(); _initUserOnload(); return true; } var sClass = _s.oMC.className, wasTimeout = (_s.useFlashBlock && _s.flashLoadTimeout && !_s.getMoviePercent()); if (!wasTimeout) { _didInit = true; } _s._wD("-- SoundManager 2 " + (_disabled ? "failed to load" : "loaded") + " (" + (_disabled ? "security/load error" : "OK") + ") --", 1); if (_disabled || bNoDisable) { if (_s.useFlashBlock) { _s.oMC.className = _getSWFCSS() + " " + (_s.getMoviePercent() === null ? _s.swfCSS.swfTimedout : _s.swfCSS.swfError); } _processOnEvents({ type: "ontimeout" }); _debugTS("onload", false); if (_s.onerror instanceof Function) { _s.onerror.apply(_win); } return false; } else { _debugTS("onload", true); } _event.add(window, "unload", _doNothing); if (_s.waitForWindowLoad && !_windowLoaded) { _wDS("waitOnload"); _event.add(_win, "load", _initUserOnload); return false; } else { if (_s.waitForWindowLoad && _windowLoaded) { _wDS("docLoaded"); } _initUserOnload(); } return true; }; _addOnEvent = function (sType, oMethod, oScope) { if (typeof _on_queue[sType] === "undefined") { _on_queue[sType] = []; } _on_queue[sType].push({ method: oMethod, scope: (oScope || null), fired: false }); }; _processOnEvents = function (oOptions) { if (!oOptions) { oOptions = { type: "onready" }; } if (!_didInit && oOptions && !oOptions.ignoreInit) { return false; } var status = { success: (oOptions && oOptions.ignoreInit ? _s.ok() : !_disabled) }, srcQueue = (oOptions && oOptions.type ? _on_queue[oOptions.type] || [] : []), queue = [], i, j, canRetry = (_needsFlash && _s.useFlashBlock && !_s.ok()); for (i = 0; i < srcQueue.length; i++) { if (srcQueue[i].fired !== true) { queue.push(srcQueue[i]); } } if (queue.length) { _s._wD(_sm + ": Firing " + queue.length + " " + oOptions.type + "() item" + (queue.length === 1 ? "" : "s")); for (i = 0, j = queue.length; i < j; i++) { if (queue[i].scope) { queue[i].method.apply(queue[i].scope, [status]); } else { queue[i].method(status); } if (!canRetry) { queue[i].fired = true; } } } return true; }; _initUserOnload = function () { _win.setTimeout(function () { if (_s.useFlashBlock) { _flashBlockHandler(); } _processOnEvents(); if (_s.onload instanceof Function) { _wDS("onload", 1); _s.onload.apply(_win); _wDS("onloadOK", 1); } if (_s.waitForWindowLoad) { _event.add(_win, "load", _initUserOnload); } }, 1); }; _featureCheck = function () { var needsFlash, item, isBadSafari = (!_wl.match(/usehtml5audio/i) && !_wl.match(/sm2\-ignorebadua/i) && _isSafari && _ua.match(/OS X 10_6_(3|4|5)/i)), isSpecial = (_ua.match(/iphone os (1|2|3_0|3_1)/i) ? true : false); if (isSpecial) { _s.hasHTML5 = false; _html5Only = true; if (_s.oMC) { _s.oMC.style.display = "none"; } return false; } if (_s.useHTML5Audio) { if (!_s.html5 || !_s.html5.canPlayType) { _s._wD("SoundManager: No HTML5 Audio() support detected."); _s.hasHTML5 = false; return true; } else { _s.hasHTML5 = true; } if (isBadSafari) { _s._wD("SoundManager::Note: Buggy HTML5 Audio in Safari on OS X 10.6.[3|4|5], see https://bugs.webkit.org/show_bug.cgi?id=32159 - disabling HTML5 audio", 1); _s.useHTML5Audio = false; _s.hasHTML5 = false; return true; } } else { return true; } for (item in _s.audioFormats) { if (_s.audioFormats.hasOwnProperty(item) && _s.audioFormats[item].required && !_s.html5.canPlayType(_s.audioFormats[item].type)) { needsFlash = true; } } if (_s.ignoreFlash) { needsFlash = false; } _html5Only = (_s.useHTML5Audio && _s.hasHTML5 && !needsFlash); return needsFlash; }; _init = function () { var item, tests = []; _wDS("init"); if (_didInit) { _wDS("didInit"); return false; } function _cleanup() { _event.remove(_win, "load", _s.beginDelayedInit); } if (_s.hasHTML5) { for (item in _s.audioFormats) { if (_s.audioFormats.hasOwnProperty(item)) { tests.push(item + ": " + _s.html5[item]); } } _s._wD("-- SoundManager 2: HTML5 support tests (" + _s.html5Test + "): " + tests.join(", ") + " --", 1); } if (_html5Only) { if (!_didInit) { _cleanup(); _s.enabled = true; _initComplete(); } return true; } _initMovie(); try { _wDS("flashJS"); _s.o._externalInterfaceTest(false); if (!_s.allowPolling) { _wDS("noPolling", 1); } else { _setPolling(true, _s.flashPollingInterval ? _s.flashPollingInterval : (_s.useFastPolling ? 10 : 50)); } if (!_s.debugMode) { _s.o._disableDebug(); } _s.enabled = true; _debugTS("jstoflash", true); } catch (e) { _s._wD("js/flash exception: " + e.toString()); _debugTS("jstoflash", false); _failSafely(true); _initComplete(); return false; } _initComplete(); _cleanup(); return true; }; _beginInit = function () { if (_initPending) { return false; } _createMovie(); _initMovie(); _initPending = true; return true; }; _dcLoaded = function () { if (_didDCLoaded) { return false; } _didDCLoaded = true; _initDebug(); _testHTML5(); _s.html5.usingFlash = _featureCheck(); _needsFlash = _s.html5.usingFlash; _didDCLoaded = true; if (_doc.removeEventListener) { _doc.removeEventListener("DOMContentLoaded", _dcLoaded, false); } _go(); return true; }; _startTimer = function (oSound) { if (!oSound._hasTimer) { oSound._hasTimer = true; } }; _stopTimer = function (oSound) { if (oSound._hasTimer) { oSound._hasTimer = false; } }; _die = function () { if (_s.onerror instanceof Function) { _s.onerror(); } _s.disable(); }; this._setSandboxType = function (sandboxType) { var sb = _s.sandbox; sb.type = sandboxType; sb.description = sb.types[(typeof sb.types[sandboxType] !== "undefined" ? sandboxType : "unknown")]; _s._wD("Flash security sandbox type: " + sb.type); if (sb.type === "localWithFile") { sb.noRemote = true; sb.noLocal = false; _wDS("secNote", 2); } else { if (sb.type === "localWithNetwork") { sb.noRemote = false; sb.noLocal = true; } else { if (sb.type === "localTrusted") { sb.noRemote = false; sb.noLocal = false; } } } }; this._externalInterfaceOK = function (flashDate) { if (_s.swfLoaded) { return false; } var eiTime = new Date().getTime(); _s._wD("soundManager::externalInterfaceOK()" + (flashDate ? " (~" + (eiTime - flashDate) + " ms)" : "")); _debugTS("swf", true); _debugTS("flashtojs", true); _s.swfLoaded = true; _tryInitOnFocus = false; if (_isIE) { setTimeout(_init, 100); } else { _init(); } }; _dcIE = function () { if (_doc.readyState === "complete") { _dcLoaded(); _doc.detachEvent("onreadystatechange", _dcIE); } return true; }; if (!_s.hasHTML5 || _needsFlash) { _event.add(_win, "focus", _handleFocus); _event.add(_win, "load", _handleFocus); _event.add(_win, "load", _delayWaitForEI); if (_isSafari && _tryInitOnFocus) { _event.add(_win, "mousemove", _handleFocus); } } if (_doc.addEventListener) { _doc.addEventListener("DOMContentLoaded", _dcLoaded, false); } else { if (_doc.attachEvent) { _doc.attachEvent("onreadystatechange", _dcIE); } else { _debugTS("onload", false); _die(); } } if (_doc.readyState === "complete") { setTimeout(_dcLoaded, 100); } } if (typeof SM2_DEFER === "undefined" || !SM2_DEFER) { soundManager = new SoundManager(); } window.SoundManager = SoundManager; window.soundManager = soundManager; } (window)); var pagePlayer = null; function PagePlayer() { var self = this, pl = this, sm = soundManager, _event, vuDataCanvas = null, controlTemplate = null, _head = document.getElementsByTagName("head")[0], spectrumContainer = null, ua = navigator.userAgent, supportsFavicon = (ua.match(/(opera|firefox)/i)), isTouchDevice = (ua.match(/ipad|ipod|iphone/i)), cleanup; this.config = { usePeakData: false, useWaveformData: false, useEQData: false, fillGraph: false, useMovieStar: true, allowRightClick: true, useThrottling: true, autoStart: false, playNext: true, updatePageTitle: false, emptyTime: "-:--", useFavIcon: false }; this.css = { sDefault: "sm2_link", sLoading: "sm2_loading", sPlaying: "sm2_playing", sPaused: "sm2_paused" }; sm.debugMode = (window.location.href.toString().match(/debug=1/i) ? true : false); this.sounds = []; this.soundsByObject = []; this.lastSound = null; this.soundCount = 0; this.strings = []; this.dragActive = false; this.dragExec = new Date(); this.dragTimer = null; this.pageTitle = document.title; this.lastWPExec = new Date(); this.lastWLExec = new Date(); this.vuMeterData = []; this.oControls = null; this._mergeObjects = function (oMain, oAdd) { var o1 = {}, o2, i, o; for (i in oMain) { if (oMain.hasOwnProperty(i)) { o1[i] = oMain[i]; } } o2 = (typeof oAdd === "undefined" ? {} : oAdd); for (o in o2) { if (typeof o1[o] === "undefined") { o1[o] = o2[o]; } } return o1; }; _event = (function () { var old = (window.attachEvent && !window.addEventListener), _slice = Array.prototype.slice, evt = { add: (old ? "attachEvent" : "addEventListener"), remove: (old ? "detachEvent" : "removeEventListener") }; function getArgs(oArgs) { var args = _slice.call(oArgs), len = args.length; if (old) { args[1] = "on" + args[1]; if (len > 3) { args.pop(); } } else { if (len === 3) { args.push(false); } } return args; } function apply(args, sType) { var element = args.shift(), method = [evt[sType]]; if (old) { element[method](args[0], args[1]); } else { element[method].apply(element, args); } } function add() { apply(getArgs(arguments), "add"); } function remove() { apply(getArgs(arguments), "remove"); } return { add: add, remove: remove }; } ()); this.hasClass = function (o, cStr) { return (typeof (o.className) !== "undefined" ? new RegExp("(^|\\s)" + cStr + "(\\s|$)").test(o.className) : false); }; this.addClass = function (o, cStr) { if (!o || !cStr || self.hasClass(o, cStr)) { return false; } o.className = (o.className ? o.className + " " : "") + cStr; }; this.removeClass = function (o, cStr) { if (!o || !cStr || !self.hasClass(o, cStr)) { return false; } o.className = o.className.replace(new RegExp("( " + cStr + ")|(" + cStr + ")", "g"), ""); }; this.select = function (className, oParent) { var result = self.getByClassName(className, "div", oParent || null); return (result ? result[0] : null); }; this.getByClassName = (document.querySelectorAll ? function (className, tagNames, oParent) { var pattern = ("." + className), qs; if (tagNames) { tagNames = tagNames.split(" "); } qs = (tagNames.length > 1 ? tagNames.join(pattern + ", ") : tagNames[0] + pattern); return (oParent ? oParent : document).querySelectorAll(qs); } : function (className, tagNames, oParent) { var node = (oParent ? oParent : document), matches = [], i, j, nodes = []; if (tagNames) { tagNames = tagNames.split(" "); } if (tagNames instanceof Array) { for (i = tagNames.length; i--; ) { if (!nodes || !nodes[tagNames[i]]) { nodes[tagNames[i]] = node.getElementsByTagName(tagNames[i]); } } for (i = tagNames.length; i--; ) { for (j = nodes[tagNames[i]].length; j--; ) { if (self.hasClass(nodes[tagNames[i]][j], className)) { matches.push(nodes[tagNames[i]][j]); } } } } else { nodes = node.all || node.getElementsByTagName("*"); for (i = 0, j = nodes.length; i < j; i++) { if (self.hasClass(nodes[i], className)) { matches.push(nodes[i]); } } } return matches; }); this.isChildOfClass = function (oChild, oClass) { if (!oChild || !oClass) { return false; } while (oChild.parentNode && !self.hasClass(oChild, oClass)) { oChild = oChild.parentNode; } return (self.hasClass(oChild, oClass)); }; this.getParentByNodeName = function (oChild, sParentNodeName) { if (!oChild || !sParentNodeName) { return false; } sParentNodeName = sParentNodeName.toLowerCase(); while (oChild.parentNode && sParentNodeName !== oChild.parentNode.nodeName.toLowerCase()) { oChild = oChild.parentNode; } return (oChild.parentNode && sParentNodeName === oChild.parentNode.nodeName.toLowerCase() ? oChild.parentNode : null); }; this.getOffX = function (o) { var curleft = 0; if (o.offsetParent) { while (o.offsetParent) { curleft += o.offsetLeft; o = o.offsetParent; } } else { if (o.x) { curleft += o.x; } } return curleft; }; this.getTime = function (nMSec, bAsString) { var nSec = Math.floor(nMSec / 1000), min = Math.floor(nSec / 60), sec = nSec - (min * 60); return (bAsString ? (min + ":" + (sec < 10 ? "0" + sec : sec)) : { min: min, sec: sec }); }; this.getSoundByObject = function (o) { return (typeof self.soundsByObject[o.id] !== "undefined" ? self.soundsByObject[o.id] : null); }; this.getNextItem = function (o) { if (o.nextElementSibling) { o = o.nextElementSibling; } else { o = o.nextSibling; while (o && o.nextSibling && o.nextSibling.nodeType !== 1) { o = o.nextSibling; } } if (o.nodeName.toLowerCase() !== "li") { return null; } else { return o.getElementsByTagName("a")[0]; } }; this.playNext = function (oSound) { if (!oSound) { oSound = self.lastSound; } if (!oSound) { return false; } var nextItem = self.getNextItem(oSound._data.oLI); if (nextItem) { pl.handleClick({ target: nextItem }); } return nextItem; }; this.setPageTitle = function (sTitle) { if (!self.config.updatePageTitle) { return false; } try { document.title = (sTitle ? sTitle + " - " : "") + self.pageTitle; } catch (e) { self.setPageTitle = function () { return false; }; } }; this.events = { play: function () { pl.removeClass(this._data.oLI, this._data.className); this._data.className = pl.css.sPlaying; pl.addClass(this._data.oLI, this._data.className); self.setPageTitle(this._data.originalTitle); }, stop: function () { pl.removeClass(this._data.oLI, this._data.className); this._data.className = ""; this._data.oPosition.style.width = "0px"; self.setPageTitle(); self.resetPageIcon(); }, pause: function () { if (pl.dragActive) { return false; } pl.removeClass(this._data.oLI, this._data.className); this._data.className = pl.css.sPaused; pl.addClass(this._data.oLI, this._data.className); self.setPageTitle(); self.resetPageIcon(); }, resume: function () { if (pl.dragActive) { return false; } pl.removeClass(this._data.oLI, this._data.className); this._data.className = pl.css.sPlaying; pl.addClass(this._data.oLI, this._data.className); }, finish: function () { pl.removeClass(this._data.oLI, this._data.className); this._data.className = ""; this._data.oPosition.style.width = "0px"; if (self.config.playNext) { pl.playNext(this); } else { self.setPageTitle(); self.resetPageIcon(); } }, whileloading: function () { function doWork() { this._data.oLoading.style.width = (((this.bytesLoaded / this.bytesTotal) * 100) + "%"); if (!this._data.didRefresh && this._data.metadata) { this._data.didRefresh = true; this._data.metadata.refresh(); } } if (!pl.config.useThrottling) { doWork.apply(this); } else { var d = new Date(); if (d && d - self.lastWLExec > 30 || this.bytesLoaded === this.bytesTotal) { doWork.apply(this); self.lastWLExec = d; } } }, onload: function () { if (!this.loaded) { var oTemp = this._data.oLI.getElementsByTagName("a")[0], oString = oTemp.innerHTML, oThis = this; oTemp.innerHTML = oString + ' <span style="font-size:0.5em"> | Load failed, d\'oh! ' + (sm.sandbox.noRemote ? " Possible cause: Flash sandbox is denying remote URL access." : (sm.sandbox.noLocal ? "Flash denying local filesystem access" : "404?")) + "</span>"; setTimeout(function () { oTemp.innerHTML = oString; }, 5000); } else { if (this._data.metadata) { this._data.metadata.refresh(); } } }, whileplaying: function () { var d = null; if (pl.dragActive || !pl.config.useThrottling) { self.updateTime.apply(this); if (sm.flashVersion >= 9) { if (pl.config.usePeakData && this.instanceOptions.usePeakData) { self.updatePeaks.apply(this); } if (pl.config.useWaveformData && this.instanceOptions.useWaveformData || pl.config.useEQData && this.instanceOptions.useEQData) { self.updateGraph.apply(this); } } if (this._data.metadata) { d = new Date(); if (d && d - self.lastWPExec > 500) { this._data.metadata.refreshMetadata(this); self.lastWPExec = d; } } this._data.oPosition.style.width = (((this.position / self.getDurationEstimate(this)) * 100) + "%"); } else { d = new Date(); if (d - self.lastWPExec > 30) { self.updateTime.apply(this); if (sm.flashVersion >= 9) { if (pl.config.usePeakData && this.instanceOptions.usePeakData) { self.updatePeaks.apply(this); } if (pl.config.useWaveformData && this.instanceOptions.useWaveformData || pl.config.useEQData && this.instanceOptions.useEQData) { self.updateGraph.apply(this); } } if (this._data.metadata) { this._data.metadata.refreshMetadata(this); } this._data.oPosition.style.width = (((this.position / self.getDurationEstimate(this)) * 100) + "%"); self.lastWPExec = d; } } } }; this.setPageIcon = function (sDataURL) { if (!self.config.useFavIcon || !self.config.usePeakData || !sDataURL) { return false; } var link = document.getElementById("sm2-favicon"); if (link) { _head.removeChild(link); link = null; } if (!link) { link = document.createElement("link"); link.id = "sm2-favicon"; link.rel = "shortcut icon"; link.type = "image/png"; link.href = sDataURL; document.getElementsByTagName("head")[0].appendChild(link); } }; this.resetPageIcon = function () { if (!self.config.useFavIcon) { return false; } var link = document.getElementById("favicon"); if (link) { link.href = "/favicon.ico"; } }; this.updatePeaks = function () { var o = this._data.oPeak, oSpan = o.getElementsByTagName("span"); oSpan[0].style.marginTop = (13 - (Math.floor(15 * this.peakData.left)) + "px"); oSpan[1].style.marginTop = (13 - (Math.floor(15 * this.peakData.right)) + "px"); if (sm.flashVersion > 8 && self.config.useFavIcon && self.config.usePeakData) { self.setPageIcon(self.vuMeterData[parseInt(16 * this.peakData.left, 10)][parseInt(16 * this.peakData.right, 10)]); } }; this.updateGraph = function () { if (pl.config.flashVersion < 9 || (!pl.config.useWaveformData && !pl.config.useEQData)) { return false; } var sbC = this._data.oGraph.getElementsByTagName("div"), scale, i, offset; if (pl.config.useWaveformData) { scale = 8; for (i = 255; i--; ) { sbC[255 - i].style.marginTop = (1 + scale + Math.ceil(this.waveformData.left[i] * -scale)) + "px"; } } else { offset = 9; for (i = 255; i--; ) { sbC[255 - i].style.marginTop = ((offset * 2) - 1 + Math.ceil(this.eqData[i] * -offset)) + "px"; } } }; this.resetGraph = function () { if (!pl.config.useEQData || pl.config.flashVersion < 9) { return false; } var sbC = this._data.oGraph.getElementsByTagName("div"), scale = (!pl.config.useEQData ? "9px" : "17px"), nHeight = (!pl.config.fillGraph ? "1px" : "32px"), i; for (i = 255; i--; ) { sbC[255 - i].style.marginTop = scale; sbC[255 - i].style.height = nHeight; } }; this.updateTime = function () { var str = self.strings.timing.replace("%s1", self.getTime(this.position, true)); str = str.replace("%s2", self.getTime(self.getDurationEstimate(this), true)); this._data.oTiming.innerHTML = str; }; this.getTheDamnTarget = function (e) { return (e.target || (window.event ? window.event.srcElement : null)); }; this.withinStatusBar = function (o) { return (self.isChildOfClass(o, "controls")); }; this.handleClick = function (e) { if (e.button === 2) { if (!pl.config.allowRightClick) { pl.stopEvent(e); } return pl.config.allowRightClick; } var o = self.getTheDamnTarget(e), sURL, soundURL, thisSound, oControls, oLI, str; if (!o) { return true; } if (self.dragActive) { self.stopDrag(); } if (self.withinStatusBar(o)) { return false; } if (o.nodeName.toLowerCase() !== "a") { o = self.getParentByNodeName(o, "a"); } if (!o) { return true; } sURL = o.getAttribute("href"); if (!o.href || (!sm.canPlayLink(o) && !self.hasClass(o, "playable")) || self.hasClass(o, "exclude")) { return true; } else { self.initUL(self.getParentByNodeName(o, "ul")); self.initItem(o); soundURL = o.href; thisSound = self.getSoundByObject(o); if (thisSound) { self.setPageTitle(thisSound._data.originalTitle); if (thisSound === self.lastSound) { if (thisSound.readyState !== 2) { if (thisSound.playState !== 1) { thisSound.play(); } else { thisSound.togglePause(); } } else { sm._writeDebug("Warning: sound failed to load (security restrictions, 404 or bad format)", 2); } } else { if (self.lastSound) { self.stopSound(self.lastSound); } if (spectrumContainer) { thisSound._data.oTimingBox.appendChild(spectrumContainer); } thisSound.togglePause(); } } else { thisSound = sm.createSound({ id: o.id, url: decodeURI(soundURL), onplay: self.events.play, onstop: self.events.stop, onpause: self.events.pause, onresume: self.events.resume, onfinish: self.events.finish, whileloading: self.events.whileloading, whileplaying: self.events.whileplaying, onmetadata: self.events.metadata, onload: self.events.onload }); oControls = self.oControls.cloneNode(true); oLI = o.parentNode; oLI.appendChild(oControls); if (spectrumContainer) { oLI.appendChild(spectrumContainer); } self.soundsByObject[o.id] = thisSound; thisSound._data = { oLink: o, oLI: oLI, oControls: self.select("controls", oLI), oStatus: self.select("statusbar", oLI), oLoading: self.select("loading", oLI), oPosition: self.select("position", oLI), oTimingBox: self.select("timing", oLI), oTiming: self.select("timing", oLI).getElementsByTagName("div")[0], oPeak: self.select("peak", oLI), oGraph: self.select("spectrum-box", oLI), className: self.css.sPlaying, originalTitle: o.innerHTML, metadata: null }; if (spectrumContainer) { thisSound._data.oTimingBox.appendChild(spectrumContainer); } if (thisSound._data.oLI.getElementsByTagName("ul").length) { thisSound._data.metadata = new Metadata(thisSound); } str = self.strings.timing.replace("%s1", self.config.emptyTime); str = str.replace("%s2", self.config.emptyTime); thisSound._data.oTiming.innerHTML = str; self.sounds.push(thisSound); if (self.lastSound) { self.stopSound(self.lastSound); } self.resetGraph.apply(thisSound); thisSound.play(); } self.lastSound = thisSound; return self.stopEvent(e); } }; this.handleMouseDown = function (e) { if (isTouchDevice && e.touches) { e = e.touches[0]; } if (e.button === 2) { if (!pl.config.allowRightClick) { pl.stopEvent(e); } return pl.config.allowRightClick; } var o = self.getTheDamnTarget(e); if (!o) { return true; } if (!self.withinStatusBar(o)) { return true; } self.dragActive = true; self.lastSound.pause(); self.setPosition(e); if (!isTouchDevice) { _event.add(document, "mousemove", self.handleMouseMove); } else { _event.add(document, "touchmove", self.handleMouseMove); } self.addClass(self.lastSound._data.oControls, "dragging"); return self.stopEvent(e); }; this.handleMouseMove = function (e) { if (isTouchDevice && e.touches) { e = e.touches[0]; } if (self.dragActive) { if (self.config.useThrottling) { var d = new Date(); if (d - self.dragExec > 20) { self.setPosition(e); } else { window.clearTimeout(self.dragTimer); self.dragTimer = window.setTimeout(function () { self.setPosition(e); }, 20); } self.dragExec = d; } else { self.setPosition(e); } } else { self.stopDrag(); } e.stopPropagation = true; return false; }; this.stopDrag = function (e) { if (self.dragActive) { self.removeClass(self.lastSound._data.oControls, "dragging"); if (!isTouchDevice) { _event.remove(document, "mousemove", self.handleMouseMove); } else { _event.remove(document, "touchmove", self.handleMouseMove); } if (!pl.hasClass(self.lastSound._data.oLI, self.css.sPaused)) { self.lastSound.resume(); } self.dragActive = false; return self.stopEvent(e); } }; this.handleStatusClick = function (e) { self.setPosition(e); if (!pl.hasClass(self.lastSound._data.oLI, self.css.sPaused)) { self.resume(); } return self.stopEvent(e); }; this.stopEvent = function (e) { if (typeof e !== "undefined") { if (typeof e.preventDefault !== "undefined") { e.preventDefault(); } else { e.stopPropagation = true; e.returnValue = false; } } return false; }; this.setPosition = function (e) { var oThis = self.getTheDamnTarget(e), x, oControl, oSound, nMsecOffset; if (!oThis) { return true; } oControl = oThis; while (!self.hasClass(oControl, "controls") && oControl.parentNode) { oControl = oControl.parentNode; } oSound = self.lastSound; x = parseInt(e.clientX, 10); nMsecOffset = Math.floor((x - self.getOffX(oControl) - 4) / (oControl.offsetWidth) * self.getDurationEstimate(oSound)); if (!isNaN(nMsecOffset)) { nMsecOffset = Math.min(nMsecOffset, oSound.duration); } if (!isNaN(nMsecOffset)) { oSound.setPosition(nMsecOffset); } }; this.stopSound = function (oSound) { sm._writeDebug("stopping sound: " + oSound.sID); sm.stop(oSound.sID); sm.unload(oSound.sID); }; this.getDurationEstimate = function (oSound) { if (oSound.instanceOptions.isMovieStar) { return (oSound.duration); } else { return (!oSound._data.metadata || !oSound._data.metadata.data.givenDuration ? (oSound.durationEstimate || 0) : oSound._data.metadata.data.givenDuration); } }; this.createVUData = function () { var i = 0, j = 0, canvas = vuDataCanvas.getContext("2d"), vuGrad = canvas.createLinearGradient(0, 16, 0, 0), bgGrad, outline; vuGrad.addColorStop(0, "rgb(0,192,0)"); vuGrad.addColorStop(0.3, "rgb(0,255,0)"); vuGrad.addColorStop(0.625, "rgb(255,255,0)"); vuGrad.addColorStop(0.85, "rgb(255,0,0)"); bgGrad = canvas.createLinearGradient(0, 16, 0, 0); outline = "rgba(0,0,0,0.2)"; bgGrad.addColorStop(0, outline); bgGrad.addColorStop(1, "rgba(0,0,0,0.5)"); for (i = 0; i < 16; i++) { self.vuMeterData[i] = []; } for (i = 0; i < 16; i++) { for (j = 0; j < 16; j++) { vuDataCanvas.setAttribute("width", 16); vuDataCanvas.setAttribute("height", 16); canvas.fillStyle = bgGrad; canvas.fillRect(0, 0, 7, 15); canvas.fillRect(8, 0, 7, 15); canvas.fillStyle = vuGrad; canvas.fillRect(0, 15 - i, 7, 16 - (16 - i)); canvas.fillRect(8, 15 - j, 7, 16 - (16 - j)); canvas.clearRect(0, 3, 16, 1); canvas.clearRect(0, 7, 16, 1); canvas.clearRect(0, 11, 16, 1); self.vuMeterData[i][j] = vuDataCanvas.toDataURL("image/png"); } } }; this.testCanvas = function () { var c = document.createElement("canvas"), ctx = null, ok; if (!c || typeof c.getContext === "undefined") { return null; } ctx = c.getContext("2d"); if (!ctx || typeof c.toDataURL !== "function") { return null; } try { ok = c.toDataURL("image/png"); } catch (e) { return null; } return c; }; this.initItem = function (oNode) { if (!oNode.id) { oNode.id = "pagePlayerMP3Sound" + (self.soundCount++); } self.addClass(oNode, self.css.sDefault); }; this.initUL = function (oULNode) { if (sm.flashVersion >= 9) { self.addClass(oULNode, self.cssBase); } }; this.init = function (oConfig) { if (oConfig) { sm._writeDebug("pagePlayer.init(): Using custom configuration"); this.config = this._mergeObjects(oConfig, this.config); } else { sm._writeDebug("pagePlayer.init(): Using default configuration"); } var i, spectrumBox, sbC, oF, oClone, oTiming; this.cssBase = []; sm.useFlashBlock = true; if (sm.flashVersion >= 9) { sm.useMovieStar = this.config.useMovieStar; sm.defaultOptions.usePeakData = this.config.usePeakData; sm.defaultOptions.useWaveformData = this.config.useWaveformData; sm.defaultOptions.useEQData = this.config.useEQData; if (this.config.usePeakData) { this.cssBase.push("use-peak"); } if (this.config.useWaveformData || this.config.useEQData) { this.cssBase.push("use-spectrum"); } this.cssBase = this.cssBase.join(" "); if (this.config.useFavIcon) { vuDataCanvas = self.testCanvas(); if (vuDataCanvas && supportsFavicon) { self.createVUData(); } else { this.config.useFavIcon = false; } } } else { if (this.config.usePeakData || this.config.useWaveformData || this.config.useEQData) { sm._writeDebug("Page player: Note: soundManager.flashVersion = 9 is required for peak/waveform/EQ features."); } } controlTemplate = document.createElement("div"); controlTemplate.innerHTML = ['  <div class="controls">', '   <div class="statusbar">', '    <div class="loading"></div>', '    <div class="position"></div>', "   </div>", "  </div>", '  <div class="timing">', '   <div id="sm2_timing" class="timing-data">', '    <span class="sm2_position">%s1</span> / <span class="sm2_total">%s2</span>', "   </div>", "  </div>", '  <div class="peak">', '   <div class="peak-box"><span class="l"></span><span class="r"></span></div>', "  </div>", ' <div class="spectrum-container">', '  <div class="spectrum-box">', '   <div class="spectrum"></div>', "  </div>", " </div>"].join("\n"); if (sm.flashVersion >= 9) { spectrumContainer = self.select("spectrum-container", controlTemplate); spectrumContainer = controlTemplate.removeChild(spectrumContainer); spectrumBox = self.select("spectrum-box", spectrumContainer); sbC = spectrumBox.getElementsByTagName("div")[0]; oF = document.createDocumentFragment(); oClone = null; for (i = 256; i--; ) { oClone = sbC.cloneNode(false); oClone.style.left = (i) + "px"; oF.appendChild(oClone); } spectrumBox.removeChild(sbC); spectrumBox.appendChild(oF); } else { controlTemplate.removeChild(self.select("spectrum-container", controlTemplate)); controlTemplate.removeChild(self.select("peak", controlTemplate)); } self.oControls = controlTemplate.cloneNode(true); oTiming = self.select("timing-data", controlTemplate); self.strings.timing = oTiming.innerHTML; oTiming.innerHTML = ""; oTiming.id = ""; function doEvents(action) { _event[action](document, "click", self.handleClick); if (!isTouchDevice) { _event[action](document, "mousedown", self.handleMouseDown); _event[action](document, "mouseup", self.stopDrag); } else { _event[action](document, "touchstart", self.handleMouseDown); _event[action](document, "touchend", self.stopDrag); } _event[action](window, "unload", cleanup); } cleanup = function () { doEvents("remove"); }; doEvents("add"); sm._writeDebug("pagePlayer.init(): Ready", 1); if (self.config.autoStart) { pl.handleClick({ target: pl.getByClassName("playlist", "ul")[0].getElementsByTagName("a")[0] }); } }; } soundManager.onready(function () { pagePlayer = new PagePlayer(); pagePlayer.init(typeof PP_CONFIG !== "undefined" ? PP_CONFIG : null); });
