+++ /dev/null
-/** @license\r
- * SoundManager 2: Javascript Sound for the Web\r
- * --------------------------------------------\r
- * http://schillmania.com/projects/soundmanager2/\r
- *\r
- * Copyright (c) 2007, Scott Schiller. All rights reserved.\r
- * Code provided under the BSD License:\r
- * http://schillmania.com/projects/soundmanager2/license.txt\r
- *\r
- * V2.96a.20100822\r
- */\r
-\r
-/*jslint white: false, onevar: true, undef: true, nomen: false, eqeqeq: true, plusplus: false, bitwise: true, regexp: true, newcap: true, immed: true, regexp: false */\r
-/*global SM2_DEFER, sm2Debugger, alert, console, document, navigator, setTimeout, window, document, setInterval, clearInterval, Audio */\r
-\r
-(function(window) {\r
-\r
-var soundManager = null;\r
-\r
-function SoundManager(smURL, smID) {\r
-\r
- this.flashVersion = 8; // version of flash to require, either 8 or 9. Some API features require Flash 9.\r
- this.debugMode = true; // enable debugging output (div#soundmanager-debug, OR console if available+configured)\r
- this.debugFlash = false; // enable debugging output inside SWF, troubleshoot Flash/browser issues\r
- this.useConsole = true; // use firebug/safari console.log()-type debug console if available\r
- this.consoleOnly = false; // if console is being used, do not create/write to #soundmanager-debug\r
- this.waitForWindowLoad = false; // force SM2 to wait for window.onload() before trying to call soundManager.onload()\r
- this.nullURL = 'about:blank'; // path to "null" (empty) MP3 file, used to unload sounds (Flash 8 only)\r
- this.allowPolling = true; // allow flash to poll for status update (required for whileplaying() events, peak, sound spectrum functions to work.)\r
- this.useFastPolling = false; // uses lower flash timer interval for higher callback frequency, best combined with useHighPerformance\r
- this.useMovieStar = true; // enable support for Flash 9.0r115+ (codename "MovieStar") MPEG4 audio+video formats (AAC, M4V, FLV, MOV etc.)\r
- this.bgColor = '#ffffff'; // movie (.swf) background color, '#000000' useful if showing on-screen/full-screen video etc.\r
- this.useHighPerformance = false; // position:fixed flash movie can help increase js/flash speed, minimize lag\r
- this.flashLoadTimeout = 1000; // msec to wait for flash movie to load before failing (0 = infinity)\r
- this.wmode = null; // mode to render the flash movie in - null, transparent, opaque (last two allow layering of HTML on top)\r
- this.allowFullScreen = true; // enter full-screen (via double-click on movie) for flash 9+ video\r
- this.allowScriptAccess = 'always'; // for scripting the SWF (object/embed property), either 'always' or 'sameDomain'\r
- this.useFlashBlock = false; // *requires flashblock.css, see demos* - allow recovery from flash blockers. Wait indefinitely and apply timeout CSS to SWF, if applicable.\r
- this.useHTML5Audio = false; // Beta feature: Use HTML 5 Audio() where API is supported (most Safari, Chrome versions), Firefox (no MP3/MP4.) Ideally, transparent vs. Flash API where possible.\r
- this.html5Test = /^probably$/i; // HTML5 Audio().canPlayType() test. /^(probably|maybe)$/i if you want to be more liberal/risky.\r
-\r
- this.audioFormats = {\r
- // determines HTML5 support, flash requirements\r
- // eg. if MP3 or MP4 required, Flash fallback is used if HTML5 can't play it\r
- // shotgun approach to MIME testing due to browser variance\r
- 'mp3': {\r
- type: ['audio/mpeg; codecs="mp3"','audio/mpeg','audio/mp3','audio/MPA','audio/mpa-robust'],\r
- required: true\r
- }, \r
- 'mp4': {\r
- related: ['aac','m4a'], // additional formats under the MP4 container.\r
- type: ['audio/mp4; codecs="mp4a.40.2"','audio/aac','audio/x-m4a','audio/MP4A-LATM','audio/mpeg4-generic'],\r
- required: true\r
- },\r
- 'ogg': {\r
- type: ['audio/ogg; codecs=vorbis'],\r
- required: false\r
- },\r
- 'wav': {\r
- type: ['audio/wav; codecs="1"','audio/wav','audio/wave','audio/x-wav'],\r
- required: false\r
- }\r
- };\r
-\r
- this.defaultOptions = {\r
- 'autoLoad': false, // enable automatic loading (otherwise .load() will be called on demand with .play(), the latter being nicer on bandwidth - if you want to .load yourself, you also can)\r
- 'stream': true, // allows playing before entire file has loaded (recommended)\r
- 'autoPlay': false, // enable playing of file as soon as possible (much faster if "stream" is true)\r
- 'loops': 1, // how many times to repeat the sound (position will wrap around to 0, setPosition() will break out of loop when >0)\r
- 'onid3': null, // callback function for "ID3 data is added/available"\r
- 'onload': null, // callback function for "load finished"\r
- 'whileloading': null, // callback function for "download progress update" (X of Y bytes received)\r
- 'onplay': null, // callback for "play" start\r
- 'onpause': null, // callback for "pause"\r
- 'onresume': null, // callback for "resume" (pause toggle)\r
- 'whileplaying': null, // callback during play (position update)\r
- 'onstop': null, // callback for "user stop"\r
- 'onfinish': null, // callback function for "sound finished playing"\r
- 'onbeforefinish': null, // callback for "before sound finished playing (at [time])"\r
- 'onbeforefinishtime': 5000, // offset (milliseconds) before end of sound to trigger beforefinish (eg. 1000 msec = 1 second)\r
- 'onbeforefinishcomplete': null,// function to call when said sound finishes playing\r
- 'onjustbeforefinish': null, // callback for [n] msec before end of current sound\r
- 'onjustbeforefinishtime': 200, // [n] - if not using, set to 0 (or null handler) and event will not fire.\r
- 'multiShot': true, // let sounds "restart" or layer on top of each other when played multiple times, rather than one-shot/one at a time\r
- 'multiShotEvents': false, // fire multiple sound events (currently onfinish() only) when multiShot is enabled\r
- 'position': null, // offset (milliseconds) to seek to within loaded sound data.\r
- 'pan': 0, // "pan" settings, left-to-right, -100 to 100\r
- 'type': null, // MIME-like hint for file pattern / canPlay() tests, eg. audio/mp3\r
- 'volume': 100 // self-explanatory. 0-100, the latter being the max.\r
- };\r
-\r
- this.flash9Options = { // flash 9-only options, merged into defaultOptions if flash 9 is being used\r
- 'isMovieStar': null, // "MovieStar" MPEG4 audio/video mode. Null (default) = auto detect MP4, AAC etc. based on URL. true = force on, ignore URL\r
- 'usePeakData': false, // enable left/right channel peak (level) data\r
- 'useWaveformData': false, // enable sound spectrum (raw waveform data) - WARNING: CPU-INTENSIVE: may set CPUs on fire.\r
- 'useEQData': false, // enable sound EQ (frequency spectrum data) - WARNING: Also CPU-intensive.\r
- 'onbufferchange': null, // callback for "isBuffering" property change\r
- 'ondataerror': null // callback for waveform/eq data access error (flash playing audio in other tabs/domains)\r
- };\r
-\r
- this.movieStarOptions = { // flash 9.0r115+ MPEG4 audio/video options, merged into defaultOptions if flash 9+movieStar mode is enabled\r
- 'onmetadata': null, // callback for when video width/height etc. are received\r
- 'useVideo': false, // if loading movieStar content, whether to show video\r
- 'bufferTime': 3, // seconds of data to buffer before playback begins (null = flash default of 0.1 seconds - if AAC playback is gappy, try increasing.)\r
- 'serverURL': null, // rtmp: FMS or FMIS server to connect to, required when requesting media via RTMP or one of its variants\r
- 'onconnect': null // rtmp: callback for connection to flash media server\r
-/*\r
- 'duration': null, // rtmp: song duration (msec)\r
- 'totalbytes': null // rtmp: byte size of the song\r
-*/\r
- };\r
-\r
- this.version = null;\r
- this.versionNumber = 'V2.96a.20100822';\r
- this.movieURL = null;\r
- this.url = (smURL || null);\r
- this.altURL = null;\r
- this.swfLoaded = false;\r
- this.enabled = false;\r
- this.o = null;\r
- this.movieID = 'sm2-container';\r
- this.id = (smID || 'sm2movie');\r
- this.swfCSS = {\r
- swfDefault: 'movieContainer',\r
- swfError: 'swf_error', // SWF loaded, but SM2 couldn't start (other error)\r
- swfTimedout: 'swf_timedout',\r
- swfUnblocked: 'swf_unblocked', // or loaded OK\r
- sm2Debug: 'sm2_debug',\r
- highPerf: 'high_performance',\r
- flashDebug: 'flash_debug'\r
- };\r
- this.oMC = null;\r
- this.sounds = {};\r
- this.soundIDs = [];\r
- this.muted = false;\r
- this.isFullScreen = false; // set later by flash 9+\r
- this.isIE = (navigator.userAgent.match(/MSIE/i));\r
- this.isSafari = (navigator.userAgent.match(/safari/i));\r
- this.debugID = 'soundmanager-debug';\r
- this.debugURLParam = /([#?&])debug=1/i;\r
- this.specialWmodeCase = false;\r
- this.didFlashBlock = false;\r
-\r
- this.filePattern = null;\r
- this.filePatterns = {\r
- flash8: /\.mp3(\?.*)?$/i,\r
- flash9: /\.mp3(\?.*)?$/i\r
- };\r
-\r
- this.baseMimeTypes = /^\s*audio\/(?:x-)?(?:mp(?:eg|3))\s*(?:$|;)/i; // mp3\r
- this.netStreamMimeTypes = /^\s*audio\/(?:x-)?(?:mp(?:eg|3))\s*(?:$|;)/i; // mp3, mp4, aac etc.\r
- this.netStreamTypes = ['aac', 'flv', 'mov', 'mp4', 'm4v', 'f4v', 'm4a', 'mp4v', '3gp', '3g2']; // Flash v9.0r115+ "moviestar" formats\r
- this.netStreamPattern = new RegExp('\\.(' + this.netStreamTypes.join('|') + ')(\\?.*)?$', 'i');\r
- this.mimePattern = this.baseMimeTypes;\r
-\r
- this.features = {\r
- buffering: false,\r
- peakData: false,\r
- waveformData: false,\r
- eqData: false,\r
- movieStar: false\r
- };\r
-\r
- this.sandbox = {\r
- 'type': null,\r
- 'types': {\r
- 'remote': 'remote (domain-based) rules',\r
- 'localWithFile': 'local with file access (no internet access)',\r
- 'localWithNetwork': 'local with network (internet access only, no local access)',\r
- 'localTrusted': 'local, trusted (local+internet access)'\r
- },\r
- 'description': null,\r
- 'noRemote': null,\r
- 'noLocal': null\r
- };\r
-\r
- this.hasHTML5 = null; // switch for handling logic\r
- this.html5 = { // stores canPlayType() results, etc. read-only.\r
- // mp3: boolean\r
- // mp4: boolean\r
- usingFlash: null // set if/when flash fallback is needed\r
- }; \r
- this.ignoreFlash = false; // used for special cases (eg. iPad/iPhone/palm OS?)\r
-\r
- // --- private SM2 internals ---\r
-\r
- var SMSound,\r
- _s = this, _sm = 'soundManager', _id, _ua = navigator.userAgent, _wl = window.location.href.toString(), _fV = this.flashVersion, _doNothing, _init, _onready = [], _debugOpen = true, _debugTS, _didAppend = false, _appendSuccess = false, _didInit = false, _disabled = false, _windowLoaded = false, _wDS, _wdCount, _initComplete, _mergeObjects, _addOnReady, _processOnReady, _initUserOnload, _go, _waitForEI, _setVersionInfo, _handleFocus, _beginInit, _strings, _initMovie, _dcLoaded, _didDCLoaded, _getDocument, _createMovie, _mobileFlash, _setPolling, _debugLevels = ['log', 'info', 'warn', 'error'], _defaultFlashVersion = 8, _disableObject, _failSafely, _normalizeMovieURL, _oRemoved = null, _oRemovedHTML = null, _str, _flashBlockHandler, _getSWFCSS, _toggleDebug, _loopFix, _complain, _idCheck, _waitingForEI = false, _initPending = false, _smTimer, _onTimer, _startTimer, _stopTimer, _needsFlash = null, _featureCheck, _html5OK, _html5Only = false, _html5CanPlay, _html5Ext, _dcIE, _testHTML5,\r
- _is_pre = _ua.match(/pre\//i),\r
- _iPadOrPhone = _ua.match(/(ipad|iphone)/i),\r
- _isMobile = (_ua.match(/mobile/i) || _is_pre || _iPadOrPhone),\r
- _hasConsole = (typeof console !== 'undefined' && typeof console.log !== 'undefined'),\r
- _isFocused = (typeof document.hasFocus !== 'undefined'?document.hasFocus():null),\r
- _tryInitOnFocus = (typeof document.hasFocus === 'undefined' && this.isSafari),\r
- _okToDisable = !_tryInitOnFocus;\r
-\r
- this._use_maybe = (_wl.match(/sm2\-useHTML5Maybe\=1/i)); // temporary feature: #sm2-useHTML5Maybe=1 forces loose canPlay() check\r
- this._overHTTP = (document.location?document.location.protocol.match(/http/i):null);\r
- this.useAltURL = !this._overHTTP; // use altURL if not "online"\r
-\r
- if (_iPadOrPhone || _is_pre) {\r
- // might as well force it on Apple + Palm, flash support unlikely\r
- _s.useHTML5Audio = true;\r
- _s.ignoreFlash = true;\r
- }\r
-\r
- if (_is_pre || this._use_maybe) {\r
- // less-strict canPlayType() checking option\r
- _s.html5Test = /^(probably|maybe)$/i;\r
- }\r
-\r
- // Temporary feature: allow force of HTML5 via URL: #sm2-usehtml5audio=0 or 1\r
- // <d>\r
- (function(){\r
- var a = '#sm2-usehtml5audio=', l = _wl, b = null;\r
- if (l.indexOf(a) !== -1) {\r
- b = (l.substr(l.indexOf(a)+a.length) === '1');\r
- if (typeof console !== 'undefined' && typeof console.log !== 'undefined') {\r
- console.log((b?'Enabling ':'Disabling ')+'useHTML5Audio via URL parameter');\r
- }\r
- _s.useHTML5Audio = b;\r
- }\r
- }());\r
- // </d>\r
-\r
- // --- public API methods ---\r
-\r
- this.supported = function() {\r
- return (_needsFlash?(_didInit && !_disabled):(_s.useHTML5Audio && _s.hasHTML5));\r
- };\r
-\r
- this.getMovie = function(smID) {\r
- return _s.isIE?window[smID]:(_s.isSafari?_id(smID) || document[smID]:_id(smID));\r
- };\r
-\r
- this.loadFromXML = function(sXmlUrl) {\r
- try {\r
- _s.o._loadFromXML(sXmlUrl);\r
- } catch(e) {\r
- _failSafely();\r
- return true;\r
- }\r
- };\r
-\r
- this.createSound = function(oOptions) {\r
- var _cs = 'soundManager.createSound(): ',\r
- thisOptions = null, oSound = null, _tO = null;\r
- if (!_didInit) {\r
- throw _complain(_cs + _str('notReady'), arguments.callee.caller);\r
- }\r
- if (arguments.length === 2) {\r
- // function overloading in JS! :) ..assume simple createSound(id,url) use case\r
- oOptions = {\r
- 'id': arguments[0],\r
- 'url': arguments[1]\r
- };\r
- }\r
- thisOptions = _mergeObjects(oOptions); // inherit SM2 defaults\r
- _tO = thisOptions; // alias\r
- // <d>\r
- if (_tO.id.toString().charAt(0).match(/^[0-9]$/)) {\r
- _s._wD(_cs + _str('badID', _tO.id), 2);\r
- }\r
- _s._wD(_cs + _tO.id + ' (' + _tO.url + ')', 1);\r
- // </d>\r
- if (_idCheck(_tO.id, true)) {\r
- _s._wD(_cs + _tO.id + ' exists', 1);\r
- return _s.sounds[_tO.id];\r
- }\r
-\r
- function make() {\r
- thisOptions = _loopFix(thisOptions);\r
- _s.sounds[_tO.id] = new SMSound(_tO);\r
- _s.soundIDs.push(_tO.id);\r
- return _s.sounds[_tO.id];\r
- }\r
-\r
- if (_html5OK(_tO)) {\r
- oSound = make();\r
- _s._wD('Loading sound '+_tO.id+' from HTML5');\r
- oSound._setup_html5(_tO);\r
- } else {\r
- if (_fV > 8 && _s.useMovieStar) {\r
- if (_tO.isMovieStar === null) {\r
- _tO.isMovieStar = ((_tO.serverURL || (_tO.type?_tO.type.match(_s.netStreamPattern):false)||_tO.url.match(_s.netStreamPattern))?true:false);\r
- }\r
- if (_tO.isMovieStar) {\r
- _s._wD(_cs + 'using MovieStar handling');\r
- }\r
- if (_tO.isMovieStar) {\r
- if (_tO.usePeakData) {\r
- _wDS('noPeak');\r
- _tO.usePeakData = false;\r
- }\r
- if (_tO.loops > 1) {\r
- _wDS('noNSLoop');\r
- }\r
- }\r
- }\r
- oSound = make();\r
- // flash AS2\r
- if (_fV === 8) {\r
- _s.o._createSound(_tO.id, _tO.onjustbeforefinishtime, _tO.loops||1);\r
- } else {\r
- _s.o._createSound(_tO.id, _tO.url, _tO.onjustbeforefinishtime, _tO.usePeakData, _tO.useWaveformData, _tO.useEQData, _tO.isMovieStar, (_tO.isMovieStar?_tO.useVideo:false), (_tO.isMovieStar?_tO.bufferTime:false), _tO.loops||1, _tO.serverURL, _tO.duration||null, _tO.totalBytes||null, _tO.autoPlay, true);\r
- if (!_tO.serverURL) {\r
- // We are connected immediately\r
- oSound.connected = true;\r
- if (_tO.onconnect) {\r
- _tO.onconnect.apply(oSound);\r
- }\r
- }\r
- }\r
- } \r
-\r
- if (_tO.autoLoad || _tO.autoPlay) {\r
- if (oSound) {\r
- if (_s.isHTML5) {\r
- oSound.autobuffer = 'auto'; // early HTML5 implementation (non-standard)\r
- oSound.preload = 'auto'; // standard\r
- } else {\r
- oSound.load(_tO);\r
- }\r
- }\r
- }\r
- if (_tO.autoPlay) {\r
- oSound.play();\r
- }\r
- return oSound;\r
- };\r
-\r
- this.createVideo = function(oOptions) {\r
- var fN = 'soundManager.createVideo(): ';\r
- if (arguments.length === 2) {\r
- oOptions = {\r
- 'id': arguments[0],\r
- 'url': arguments[1]\r
- };\r
- }\r
- if (_fV >= 9) {\r
- oOptions.isMovieStar = true;\r
- oOptions.useVideo = true;\r
- } else {\r
- _s._wD(fN + _str('f9Vid'), 2);\r
- return false;\r
- }\r
- if (!_s.useMovieStar) {\r
- _s._wD(fN + _str('noMS'), 2);\r
- }\r
- return _s.createSound(oOptions);\r
- };\r
-\r
- this.destroySound = function(sID, bFromSound) {\r
- // explicitly destroy a sound before normal page unload, etc.\r
- if (!_idCheck(sID)) {\r
- return false;\r
- }\r
- for (var i = 0; i < _s.soundIDs.length; i++) {\r
- if (_s.soundIDs[i] === sID) {\r
- _s.soundIDs.splice(i, 1);\r
- continue;\r
- }\r
- }\r
- _s.sounds[sID].unload();\r
- if (!bFromSound) {\r
- // ignore if being called from SMSound instance\r
- _s.sounds[sID].destruct();\r
- }\r
- delete _s.sounds[sID];\r
- };\r
-\r
- this.destroyVideo = this.destroySound;\r
-\r
- this.load = function(sID, oOptions) {\r
- if (!_idCheck(sID)) {\r
- return false;\r
- }\r
- return _s.sounds[sID].load(oOptions);\r
- };\r
-\r
- this.unload = function(sID) {\r
- if (!_idCheck(sID)) {\r
- return false;\r
- }\r
- return _s.sounds[sID].unload();\r
- };\r
-\r
- this.play = function(sID, oOptions) {\r
- var fN = 'soundManager.play(): ';\r
- if (!_didInit) {\r
- throw _complain(fN + _str('notReady'), arguments.callee.caller);\r
- }\r
- if (!_idCheck(sID)) {\r
- if (!(oOptions instanceof Object)) {\r
- oOptions = {\r
- url: oOptions\r
- }; // overloading use case: play('mySound','/path/to/some.mp3');\r
- }\r
- if (oOptions && oOptions.url) {\r
- // overloading use case, creation+playing of sound: .play('someID',{url:'/path/to.mp3'});\r
- _s._wD(fN + 'attempting to create "' + sID + '"', 1);\r
- oOptions.id = sID;\r
- return _s.createSound(oOptions).play();\r
- } else {\r
- return false;\r
- }\r
- }\r
- return _s.sounds[sID].play(oOptions);\r
- };\r
-\r
- this.start = this.play; // just for convenience\r
-\r
- this.setPosition = function(sID, nMsecOffset) {\r
- if (!_idCheck(sID)) {\r
- return false;\r
- }\r
- return _s.sounds[sID].setPosition(nMsecOffset);\r
- };\r
-\r
- this.stop = function(sID) {\r
- if (!_idCheck(sID)) {\r
- return false;\r
- }\r
- _s._wD('soundManager.stop(' + sID + ')', 1);\r
- return _s.sounds[sID].stop();\r
- };\r
-\r
- this.stopAll = function() {\r
- _s._wD('soundManager.stopAll()', 1);\r
- for (var oSound in _s.sounds) {\r
- if (_s.sounds[oSound] instanceof SMSound) {\r
- _s.sounds[oSound].stop(); // apply only to sound objects\r
- }\r
- }\r
- };\r
-\r
- this.pause = function(sID) {\r
- if (!_idCheck(sID)) {\r
- return false;\r
- }\r
- return _s.sounds[sID].pause();\r
- };\r
-\r
- this.pauseAll = function() {\r
- for (var i = _s.soundIDs.length; i--;) {\r
- _s.sounds[_s.soundIDs[i]].pause();\r
- }\r
- };\r
-\r
- this.resume = function(sID) {\r
- if (!_idCheck(sID)) {\r
- return false;\r
- }\r
- return _s.sounds[sID].resume();\r
- };\r
-\r
- this.resumeAll = function() {\r
- for (var i = _s.soundIDs.length; i--;) {\r
- _s.sounds[_s.soundIDs[i]].resume();\r
- }\r
- };\r
-\r
- this.togglePause = function(sID) {\r
- if (!_idCheck(sID)) {\r
- return false;\r
- }\r
- return _s.sounds[sID].togglePause();\r
- };\r
-\r
- this.setPan = function(sID, nPan) {\r
- if (!_idCheck(sID)) {\r
- return false;\r
- }\r
- return _s.sounds[sID].setPan(nPan);\r
- };\r
-\r
- this.setVolume = function(sID, nVol) {\r
- if (!_idCheck(sID)) {\r
- return false;\r
- }\r
- return _s.sounds[sID].setVolume(nVol);\r
- };\r
-\r
- this.mute = function(sID) {\r
- var fN = 'soundManager.mute(): ',\r
- i = 0;\r
- if (typeof sID !== 'string') {\r
- sID = null;\r
- }\r
- if (!sID) {\r
- _s._wD(fN + 'Muting all sounds');\r
- for (i = _s.soundIDs.length; i--;) {\r
- _s.sounds[_s.soundIDs[i]].mute();\r
- }\r
- _s.muted = true;\r
- } else {\r
- if (!_idCheck(sID)) {\r
- return false;\r
- }\r
- _s._wD(fN + 'Muting "' + sID + '"');\r
- return _s.sounds[sID].mute();\r
- }\r
- };\r
-\r
- this.muteAll = function() {\r
- _s.mute();\r
- };\r
-\r
- this.unmute = function(sID) {\r
- var fN = 'soundManager.unmute(): ', i;\r
- if (typeof sID !== 'string') {\r
- sID = null;\r
- }\r
- if (!sID) {\r
- _s._wD(fN + 'Unmuting all sounds');\r
- for (i = _s.soundIDs.length; i--;) {\r
- _s.sounds[_s.soundIDs[i]].unmute();\r
- }\r
- _s.muted = false;\r
- } else {\r
- if (!_idCheck(sID)) {\r
- return false;\r
- }\r
- _s._wD(fN + 'Unmuting "' + sID + '"');\r
- return _s.sounds[sID].unmute();\r
- }\r
- };\r
-\r
- this.unmuteAll = function() {\r
- _s.unmute();\r
- };\r
-\r
- this.toggleMute = function(sID) {\r
- if (!_idCheck(sID)) {\r
- return false;\r
- }\r
- return _s.sounds[sID].toggleMute();\r
- };\r
-\r
- this.getMemoryUse = function() {\r
- if (_fV === 8) {\r
- // not supported in Flash 8\r
- return 0;\r
- }\r
- if (_s.o) {\r
- return parseInt(_s.o._getMemoryUse(), 10);\r
- }\r
- };\r
-\r
- this.disable = function(bNoDisable) {\r
- // destroy all functions\r
- if (typeof bNoDisable === 'undefined') {\r
- bNoDisable = false;\r
- }\r
- if (_disabled) {\r
- return false;\r
- }\r
- _disabled = true;\r
- _wDS('shutdown', 1);\r
- for (var i = _s.soundIDs.length; i--;) {\r
- _disableObject(_s.sounds[_s.soundIDs[i]]);\r
- }\r
- _initComplete(bNoDisable); // fire "complete", despite fail\r
- if (window.removeEventListener) {\r
- window.removeEventListener('load', _initUserOnload, false);\r
- }\r
- // _disableObject(_s); // taken out to allow reboot()\r
- };\r
-\r
- this.canPlayMIME = function(sMIME) {\r
- var result;\r
- if (_s.hasHTML5) {\r
- result = _html5CanPlay({type:sMIME});\r
- }\r
- if (!_needsFlash || result) {\r
- // no flash, or OK\r
- return result;\r
- } else {\r
- return (sMIME?(sMIME.match(_s.mimePattern)?true:false):null);\r
- }\r
- };\r
-\r
- this.canPlayURL = function(sURL) {\r
- var result;\r
- if (_s.hasHTML5) {\r
- result = _html5CanPlay(sURL);\r
- }\r
- if (!_needsFlash || result) {\r
- // no flash, or OK\r
- return result;\r
- } else {\r
- return (sURL?(sURL.match(_s.filePattern)?true:false):null);\r
- }\r
- };\r
-\r
- this.canPlayLink = function(oLink) {\r
- if (typeof oLink.type !== 'undefined' && oLink.type) {\r
- if (_s.canPlayMIME(oLink.type)) {\r
- return true;\r
- }\r
- }\r
- return _s.canPlayURL(oLink.href);\r
- };\r
-\r
- this.getSoundById = function(sID, suppressDebug) {\r
- if (!sID) {\r
- throw new Error('SoundManager.getSoundById(): sID is null/undefined');\r
- }\r
- var result = _s.sounds[sID];\r
- if (!result && !suppressDebug) {\r
- _s._wD('"' + sID + '" is an invalid sound ID.', 2);\r
- // soundManager._wD('trace: '+arguments.callee.caller);\r
- }\r
- return result;\r
- };\r
-\r
- this.onready = function(oMethod, oScope) {\r
- /*\r
- soundManager.onready(function(oStatus) {\r
- console.log('SM2 init success: '+oStatus.success);\r
- });\r
- */\r
- if (oMethod && oMethod instanceof Function) {\r
- if (_didInit) {\r
- _wDS('queue');\r
- }\r
- if (!oScope) {\r
- oScope = window;\r
- }\r
- _addOnReady(oMethod, oScope);\r
- _processOnReady();\r
- return true;\r
- } else {\r
- throw _str('needFunction');\r
- }\r
- };\r
-\r
- this.oninitmovie = function() {\r
- // called after SWF has been appended to the DOM via JS (or retrieved from HTML)\r
- // this is a stub for your own scripts.\r
- };\r
-\r
- this.onload = function() {\r
- // window.onload() equivalent for SM2, ready to create sounds etc.\r
- // this is a stub for your own scripts.\r
- _s._wD('soundManager.onload()', 1);\r
- };\r
-\r
- this.onerror = function() {\r
- // stub for user handler, called when SM2 fails to load/init\r
- };\r
-\r
- this.getMoviePercent = function() {\r
- return (_s.o && typeof _s.o.PercentLoaded !== 'undefined'?_s.o.PercentLoaded():null);\r
- };\r
-\r
- this._writeDebug = function(sText, sType, bTimestamp) {\r
- // pseudo-private console.log()-style output\r
- // <d>\r
- var sDID = 'soundmanager-debug', o, oItem, sMethod;\r
- if (!_s.debugMode) {\r
- return false;\r
- }\r
- if (typeof bTimestamp !== 'undefined' && bTimestamp) {\r
- sText = sText + ' | ' + new Date().getTime();\r
- }\r
- if (_hasConsole && _s.useConsole) {\r
- sMethod = _debugLevels[sType];\r
- if (typeof console[sMethod] !== 'undefined') {\r
- console[sMethod](sText);\r
- } else {\r
- console.log(sText);\r
- }\r
- if (_s.useConsoleOnly) {\r
- return true;\r
- }\r
- }\r
- try {\r
- o = _id(sDID);\r
- if (!o) {\r
- return false;\r
- }\r
- oItem = document.createElement('div');\r
- if (++_wdCount % 2 === 0) {\r
- oItem.className = 'sm2-alt';\r
- }\r
- // sText = sText.replace(/\n/g,'<br />');\r
- if (typeof sType === 'undefined') {\r
- sType = 0;\r
- } else {\r
- sType = parseInt(sType, 10);\r
- }\r
- oItem.appendChild(document.createTextNode(sText));\r
- if (sType) {\r
- if (sType >= 2) {\r
- oItem.style.fontWeight = 'bold';\r
- }\r
- if (sType === 3) {\r
- oItem.style.color = '#ff3333';\r
- }\r
- }\r
- // o.appendChild(oItem); // top-to-bottom\r
- o.insertBefore(oItem, o.firstChild); // bottom-to-top\r
- } catch(e) {\r
- // oh well\r
- }\r
- o = null;\r
- // </d>\r
- };\r
- this._wD = this._writeDebug; // alias\r
-\r
- this._debug = function() {\r
- // <d>\r
- _wDS('currentObj', 1);\r
- for (var i = 0, j = _s.soundIDs.length; i < j; i++) {\r
- _s.sounds[_s.soundIDs[i]]._debug();\r
- }\r
- // </d>\r
- };\r
-\r
- this.reboot = function() {\r
- // attempt to reset and init SM2\r
- _s._wD('soundManager.reboot()');\r
- if (_s.soundIDs.length) {\r
- _s._wD('Destroying ' + _s.soundIDs.length + ' SMSound objects...');\r
- }\r
- for (var i = _s.soundIDs.length; i--;) {\r
- _s.sounds[_s.soundIDs[i]].destruct();\r
- }\r
- // trash ze flash\r
- try {\r
- if (_s.isIE) {\r
- _oRemovedHTML = _s.o.innerHTML;\r
- }\r
- _oRemoved = _s.o.parentNode.removeChild(_s.o);\r
- _s._wD('Flash movie removed.');\r
- } catch(e) {\r
- // uh-oh.\r
- _wDS('badRemove', 2);\r
- }\r
- // actually, force recreate of movie.\r
- _oRemovedHTML = null;\r
- _oRemoved = null;\r
- _s.enabled = false;\r
- _didInit = false;\r
- _waitingForEI = false;\r
- _initPending = false;\r
- _didAppend = false;\r
- _appendSuccess = false;\r
- _disabled = false;\r
- _s.swfLoaded = false;\r
- _s.soundIDs = [];\r
- _s.sounds = [];\r
- _s.o = null;\r
- for (i = _onready.length; i--;) {\r
- _onready[i].fired = false;\r
- }\r
- _s._wD(_sm + ': Rebooting...');\r
- window.setTimeout(function() {\r
- _s.beginDelayedInit();\r
- }, 20);\r
- };\r
-\r
- this.destruct = function() {\r
- _s._wD('soundManager.destruct()');\r
- _s.disable(true);\r
- };\r
-\r
- this.beginDelayedInit = function() {\r
- // _s._wD('soundManager.beginDelayedInit()');\r
- _windowLoaded = true;\r
- _dcLoaded();\r
- setTimeout(_waitForEI, 500);\r
- setTimeout(_beginInit, 20);\r
- };\r
-\r
- // --- private SM2 internals ---\r
-\r
- _html5OK = function(iO) {\r
- return ((iO.type?_html5CanPlay({type:iO.type}):false)||_html5CanPlay(iO.url));\r
- };\r
-\r
- _html5CanPlay = function(sURL) {\r
- // try to find MIME, test and return truthiness\r
- if (!_s.useHTML5Audio || !_s.hasHTML5) {\r
- return false;\r
- }\r
- var result, mime, fileExt, item, aF = _s.audioFormats;\r
- if (!_html5Ext) {\r
- _html5Ext = [];\r
- for (item in aF) {\r
- if (aF.hasOwnProperty(item)) {\r
- _html5Ext.push(item);\r
- if (aF[item].related) {\r
- _html5Ext = _html5Ext.concat(aF[item].related);\r
- }\r
- }\r
- }\r
- _html5Ext = new RegExp('\\.('+_html5Ext.join('|')+')','i');\r
- }\r
- mime = (typeof sURL.type !== 'undefined'?sURL.type:null);\r
- fileExt = (typeof sURL === 'string'?sURL.toLowerCase().match(_html5Ext):null); // TODO: Strip URL queries, etc.\r
- if (!fileExt || !fileExt.length) {\r
- if (!mime) {\r
- return false;\r
- }\r
- } else {\r
- fileExt = fileExt[0].substr(1); // "mp3", for example\r
- }\r
- if (fileExt && typeof _s.html5[fileExt] !== 'undefined') {\r
- // result known\r
- return _s.html5[fileExt];\r
- } else {\r
- if (!mime) {\r
- if (fileExt && _s.html5[fileExt]) {\r
- return _s.html5[fileExt];\r
- } else {\r
- // best-case guess, audio/whatever-dot-filename-format-you're-playing\r
- mime = 'audio/'+fileExt;\r
- }\r
- }\r
- result = _s.html5.canPlayType(mime);\r
- _s.html5[fileExt] = result;\r
- // _s._wD('canPlayType, found result: '+result);\r
- return result;\r
- }\r
- };\r
-\r
- _testHTML5 = function() {\r
- if (!_s.useHTML5Audio || typeof Audio === 'undefined') {\r
- return false;\r
- }\r
- var a = (typeof Audio !== 'undefined' ? new Audio():null), item, support = {}, aF, i;\r
-\r
- function _cp(m) {\r
- var canPlay, i, j, isOK = false;\r
- if (!a || typeof a.canPlayType !== 'function') {\r
- return false;\r
- }\r
- if (m instanceof Array) {\r
- // iterate through all mime types, return any successes\r
- for (i=0, j=m.length; i<j && !isOK; i++) {\r
- if (_s.html5[m[i]] || a.canPlayType(m[i]).match(_s.html5Test)) {\r
- isOK = true;\r
- _s.html5[m[i]] = true;\r
- }\r
- }\r
- return isOK;\r
- } else {\r
- canPlay = (a && typeof a.canPlayType === 'function' ? a.canPlayType(m) : false);\r
- return (canPlay && (canPlay.match(_s.html5Test)?true:false));\r
- }\r
- }\r
-\r
- // test all registered formats + codecs\r
- aF = _s.audioFormats;\r
- for (item in aF) {\r
- if (aF.hasOwnProperty(item)) {\r
- support[item] = _cp(aF[item].type);\r
- // assign result to related formats, too\r
- if (aF[item] && aF[item].related) {\r
- for (i=0; i<aF[item].related.length; i++) {\r
- _s.html5[aF[item].related[i]] = support[item];\r
- }\r
- }\r
- }\r
- }\r
- support.canPlayType = (a?_cp:null);\r
-\r
- _s.html5 = _mergeObjects(_s.html5, support);\r
-\r
- };\r
-\r
- _strings = {\r
- notReady: 'Not loaded yet - wait for soundManager.onload() before calling sound-related methods',\r
- appXHTML: _sm + '::createMovie(): appendChild/innerHTML set failed. May be app/xhtml+xml DOM-related.',\r
- spcWmode: _sm + '::createMovie(): Removing wmode, preventing win32 below-the-fold SWF loading issue',\r
- swf404: _sm + ': Verify that %s is a valid path.',\r
- tryDebug: 'Try ' + _sm + '.debugFlash = true for more security details (output goes to SWF.)',\r
- checkSWF: 'See SWF output for more debug info.',\r
- localFail: _sm + ': Non-HTTP page (' + document.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/',\r
- waitFocus: _sm + ': Special case: Waiting for focus-related event..',\r
- waitImpatient: _sm + ': Getting impatient, still waiting for Flash%s...',\r
- waitForever: _sm + ': Waiting indefinitely for Flash (will recover if unblocked)...',\r
- needFunction: _sm + '.onready(): Function object expected',\r
- badID: 'Warning: Sound ID "%s" should be a string, starting with a non-numeric character',\r
- fl9Vid: 'flash 9 required for video. Exiting.',\r
- noMS: 'MovieStar mode not enabled. Exiting.',\r
- currentObj: '--- ' + _sm + '._debug(): Current sound objects ---',\r
- waitEI: _sm + '::initMovie(): Waiting for ExternalInterface call from Flash..',\r
- waitOnload: _sm + ': Waiting for window.onload()',\r
- docLoaded: _sm + ': Document already loaded',\r
- onload: _sm + '::initComplete(): calling soundManager.onload()',\r
- onloadOK: _sm + '.onload() complete',\r
- init: '-- ' + _sm + '::init() --',\r
- didInit: _sm + '::init(): Already called?',\r
- flashJS: _sm + ': Attempting to call Flash from JS..',\r
- noPolling: _sm + ': Polling (whileloading()/whileplaying() support) is disabled.',\r
- 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',\r
- badRemove: 'Warning: Failed to remove flash movie.',\r
- noPeak: 'Warning: peakData features unsupported for movieStar formats',\r
- shutdown: _sm + '.disable(): Shutting down',\r
- queue: _sm + '.onready(): Queueing handler',\r
- smFail: _sm + ': Failed to initialise.',\r
- smError: 'SMSound.load(): Exception: JS-Flash communication failed, or JS error.',\r
- fbTimeout: 'No flash response, applying .'+_s.swfCSS.swfTimedout+' CSS..',\r
- fbLoaded: 'Flash loaded',\r
- manURL: 'SMSound.load(): Using manually-assigned URL',\r
- onURL: _sm + '.load(): current URL already assigned.',\r
- badFV: 'soundManager.flashVersion must be 8 or 9. "%s" is invalid. Reverting to %s.',\r
- as2loop: 'Note: Setting stream:false so looping can work (flash 8 limitation)',\r
- noNSLoop: 'Note: Looping not implemented for MovieStar formats',\r
- needfl9: 'Note: Switching to flash 9, required for MP4 formats.',\r
- mfTimeout: 'Setting flashLoadTimeout = 0 (infinite) for off-screen, mobile flash case',\r
- mfOn: 'mobileFlash::enabling on-screen flash repositioning'\r
- };\r
-\r
- _id = function(sID) {\r
- return document.getElementById(sID);\r
- };\r
-\r
- _wdCount = 0;\r
-\r
- _str = function() { // o [,items to replace]\r
- var params = Array.prototype.slice.call(arguments), // real array, please\r
- o = params.shift(), // first arg\r
- str = (_strings && _strings[o]?_strings[o]:''), i, j;\r
- if (str && params && params.length) {\r
- for (i = 0, j = params.length; i < j; i++) {\r
- str = str.replace('%s', params[i]);\r
- }\r
- }\r
- return str;\r
- };\r
-\r
- _loopFix = function(sOpt) {\r
- // flash 8 requires stream = false for looping to work.\r
- if (_fV === 8 && sOpt.loops > 1 && sOpt.stream) {\r
- _wDS('as2loop');\r
- sOpt.stream = false;\r
- }\r
- return sOpt;\r
- };\r
-\r
- _complain = function(sMsg, oCaller) {\r
- // Try to create meaningful custom errors, w/stack trace to the "offending" line\r
- var sPre = 'Error: ', errorDesc;\r
- if (!oCaller) {\r
- return new Error(sPre + sMsg);\r
- }\r
- if (typeof console !== 'undefined' && typeof console.trace !== 'undefined') {\r
- console.trace();\r
- }\r
- errorDesc = sPre + sMsg + '. \nCaller: ' + oCaller.toString();\r
- // See JS error/debug/console output for real error source, stack trace / message detail where possible.\r
- return new Error(errorDesc);\r
- };\r
-\r
- _doNothing = function() {\r
- return false;\r
- };\r
-\r
- _disableObject = function(o) {\r
- for (var oProp in o) {\r
- if (o.hasOwnProperty(oProp) && typeof o[oProp] === 'function') {\r
- o[oProp] = _doNothing;\r
- }\r
- }\r
- oProp = null;\r
- };\r
-\r
- _failSafely = function(bNoDisable) {\r
- // general failure exception handler\r
- if (typeof bNoDisable === 'undefined') {\r
- bNoDisable = false;\r
- }\r
- if (_disabled || bNoDisable) {\r
- _wDS('smFail', 2);\r
- _s.disable(bNoDisable);\r
- }\r
- };\r
-\r
- _normalizeMovieURL = function(smURL) {\r
- var urlParams = null;\r
- if (smURL) {\r
- if (smURL.match(/\.swf(\?\.*)?$/i)) {\r
- urlParams = smURL.substr(smURL.toLowerCase().lastIndexOf('.swf?') + 4);\r
- if (urlParams) {\r
- return smURL; // assume user knows what they're doing\r
- }\r
- } else if (smURL.lastIndexOf('/') !== smURL.length - 1) {\r
- smURL = smURL + '/';\r
- }\r
- }\r
- return (smURL && smURL.lastIndexOf('/') !== - 1?smURL.substr(0, smURL.lastIndexOf('/') + 1):'./') + _s.movieURL;\r
- };\r
-\r
- _setVersionInfo = function() {\r
- if (_fV !== 8 && _fV !== 9) {\r
- _s._wD(_str('badFV', _fV, _defaultFlashVersion));\r
- _s.flashVersion = _defaultFlashVersion;\r
- }\r
- var isDebug = (_s.debugMode || _s.debugFlash?'_debug.swf':'.swf'); // debug flash movie, if applicable\r
- if (_s.flashVersion < 9 && _s.useHTML5Audio && _s.audioFormats.mp4.required) {\r
- _s._wD(_str('needfl9'));\r
- _s.flashVersion = 9;\r
- }\r
- _fV = _s.flashVersion; // short-hand for internal use\r
- _s.version = _s.versionNumber + (_html5Only?' (HTML5-only mode)':(_fV === 9?' (AS3/Flash 9)':' (AS2/Flash 8)'));\r
- // set up default options\r
- if (_fV > 8) {\r
- _s.defaultOptions = _mergeObjects(_s.defaultOptions, _s.flash9Options);\r
- _s.features.buffering = true;\r
- }\r
- if (_fV > 8 && _s.useMovieStar) {\r
- // flash 9+ support for movieStar formats as well as MP3\r
- _s.defaultOptions = _mergeObjects(_s.defaultOptions, _s.movieStarOptions);\r
- _s.filePatterns.flash9 = new RegExp('\\.(mp3|' + _s.netStreamTypes.join('|') + ')(\\?.*)?$', 'i');\r
- _s.mimePattern = _s.netStreamMimeTypes;\r
- _s.features.movieStar = true;\r
- } else {\r
- _s.features.movieStar = false;\r
- }\r
- _s.filePattern = _s.filePatterns[(_fV !== 8?'flash9':'flash8')];\r
- _s.movieURL = (_fV === 8?'soundmanager2.swf':'soundmanager2_flash9.swf').replace('.swf',isDebug);\r
- _s.features.peakData = _s.features.waveformData = _s.features.eqData = (_fV > 8);\r
- };\r
-\r
- _getDocument = function() {\r
- return (document.body?document.body:(document.documentElement?document.documentElement:document.getElementsByTagName('div')[0]));\r
- };\r
-\r
- _setPolling = function(bPolling, bHighPerformance) {\r
- if (!_s.o || !_s.allowPolling) {\r
- return false;\r
- }\r
- _s.o._setPolling(bPolling, bHighPerformance);\r
- };\r
-\r
- function _initDebug() {\r
- if (_s.debugURLParam.test(_wl)) {\r
- _s.debugMode = true; // allow force of debug mode via URL\r
- }\r
- // <d>\r
- var oD, oDebug, oTarget, oToggle, tmp;\r
- if (_s.debugMode) {\r
-\r
- oD = document.createElement('div');\r
- oD.id = _s.debugID + '-toggle';\r
- oToggle = {\r
- position: 'fixed',\r
- bottom: '0px',\r
- right: '0px',\r
- width: '1.2em',\r
- height: '1.2em',\r
- lineHeight: '1.2em',\r
- margin: '2px',\r
- textAlign: 'center',\r
- border: '1px solid #999',\r
- cursor: 'pointer',\r
- background: '#fff',\r
- color: '#333',\r
- zIndex: 10001\r
- };\r
-\r
- oD.appendChild(document.createTextNode('-'));\r
- oD.onclick = _toggleDebug;\r
- oD.title = 'Toggle SM2 debug console';\r
-\r
- if (_ua.match(/msie 6/i)) {\r
- oD.style.position = 'absolute';\r
- oD.style.cursor = 'hand';\r
- }\r
-\r
- for (tmp in oToggle) {\r
- if (oToggle.hasOwnProperty(tmp)) {\r
- oD.style[tmp] = oToggle[tmp];\r
- }\r
- }\r
-\r
- }\r
- if (_s.debugMode && !_id(_s.debugID) && ((!_hasConsole || !_s.useConsole) || (_s.useConsole && _hasConsole && !_s.consoleOnly))) {\r
- oDebug = document.createElement('div');\r
- oDebug.id = _s.debugID;\r
- oDebug.style.display = (_s.debugMode?'block':'none');\r
- if (_s.debugMode && !_id(oD.id)) {\r
- try {\r
- oTarget = _getDocument();\r
- oTarget.appendChild(oD);\r
- } catch(e2) {\r
- throw new Error(_str('appXHTML'));\r
- }\r
- oTarget.appendChild(oDebug);\r
- }\r
- }\r
- oTarget = null;\r
- _initDebug = function(){}; // one-time function\r
- // </d>\r
- }\r
-\r
- _mobileFlash = (function(){\r
-\r
- var oM = null;\r
-\r
- function resetPosition() {\r
- if (oM) {\r
- oM.left = oM.top = '-9999px';\r
- }\r
- }\r
-\r
- function reposition() {\r
- oM.left = window.scrollX+'px';\r
- oM.top = window.scrollY+'px';\r
- }\r
-\r
- function setReposition(bOn) {\r
- _s._wD('mobileFlash::flash on-screen hack: '+(bOn?'ON':'OFF'));\r
- var f = window[(bOn?'add':'remove')+'EventListener'];\r
- f('resize', reposition, false);\r
- f('scroll', reposition, false);\r
- }\r
-\r
- function check(inDoc) {\r
- // mobile flash (Android for starters) check\r
- oM = _s.oMC.style;\r
- if (_ua.match(/android/i)) {\r
- if (inDoc) {\r
- if (_s.flashLoadTimeout) {\r
- _s._wDS('mfTimeout');\r
- _s.flashLoadTimeout = 0;\r
- }\r
- return false;\r
- }\r
- _s._wD('mfOn');\r
- oM.position = 'absolute';\r
- oM.left = oM.top = '0px';\r
- setReposition(true);\r
- _s.onready(function(){\r
- setReposition(false); // detach\r
- resetPosition(); // restore when OK/timed out\r
- });\r
- reposition();\r
- }\r
- }\r
-\r
- return {\r
- check: check\r
- };\r
-\r
- }());\r
-\r
- _createMovie = function(smID, smURL) {\r
-\r
- var specialCase = null,\r
- remoteURL = (smURL?smURL:_s.url),\r
- localURL = (_s.altURL?_s.altURL:remoteURL),\r
- oEmbed, oMovie, oTarget, tmp, movieHTML, oEl, extraClass, s, x, sClass, side = '100%';\r
- smID = (typeof smID === 'undefined'?_s.id:smID);\r
- if (_didAppend && _appendSuccess) {\r
- return false; // ignore if already succeeded\r
- }\r
-\r
- function _initMsg() {\r
- _s._wD('-- SoundManager 2 ' + _s.version + (!_html5Only && _s.useHTML5Audio?(_s.hasHTML5?' + HTML5 audio':', no HTML5 audio support'):'') + (_s.useMovieStar?', MovieStar mode':'') + (_s.useHighPerformance?', high performance mode, ':', ') + ((_s.useFastPolling?'fast':'normal') + ' polling') + (_s.wmode?', wmode: ' + _s.wmode:'') + (_s.debugFlash?', flash debug mode':'') + (_s.useFlashBlock?', flashBlock mode':'') + ' --', 1);\r
- }\r
- if (_html5Only) {\r
- _setVersionInfo();\r
- _initMsg();\r
- _s.oMC = _id(_s.movieID);\r
- _init();\r
- // prevent multiple init attempts\r
- _didAppend = true;\r
- _appendSuccess = true;\r
- return false;\r
- }\r
-\r
- _didAppend = true;\r
-\r
- // safety check for legacy (change to Flash 9 URL)\r
- _setVersionInfo();\r
- _s.url = _normalizeMovieURL(this._overHTTP?remoteURL:localURL);\r
- smURL = _s.url;\r
-\r
- if (_s.useHighPerformance && _s.useMovieStar && _s.defaultOptions.useVideo === true) {\r
- specialCase = 'soundManager note: disabling highPerformance, not applicable with movieStar mode+useVideo';\r
- _s.useHighPerformance = false;\r
- }\r
-\r
- _s.wmode = (!_s.wmode && _s.useHighPerformance && !_s.useMovieStar?'transparent':_s.wmode);\r
-\r
- if (_s.wmode !== null && !_s.isIE && !_s.useHighPerformance && navigator.platform.match(/win32/i)) {\r
- _s.specialWmodeCase = true;\r
- // extra-special case: movie doesn't load until scrolled into view when using wmode = anything but 'window' here\r
- // does not apply when using high performance (position:fixed means on-screen), OR infinite flash load timeout\r
- _wDS('spcWmode');\r
- _s.wmode = null;\r
- }\r
-\r
- if (_fV === 8) {\r
- _s.allowFullScreen = false;\r
- }\r
-\r
- oEmbed = {\r
- name: smID,\r
- id: smID,\r
- src: smURL,\r
- width: side,\r
- height: side,\r
- quality: 'high',\r
- allowScriptAccess: _s.allowScriptAccess,\r
- bgcolor: _s.bgColor,\r
- pluginspage: 'http://www.macromedia.com/go/getflashplayer',\r
- type: 'application/x-shockwave-flash',\r
- wmode: _s.wmode,\r
- allowFullScreen: (_s.allowFullScreen?'true':'false')\r
- };\r
-\r
- if (_s.debugFlash) {\r
- oEmbed.FlashVars = 'debug=1';\r
- }\r
-\r
- if (!_s.wmode) {\r
- delete oEmbed.wmode; // don't write empty attribute\r
- }\r
-\r
- if (_s.isIE) {\r
- // IE is "special".\r
- oMovie = document.createElement('div');\r
- 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 + '" /><param name="allowFullScreen" value="' + oEmbed.allowFullScreen + '" />' + (_s.debugFlash?'<param name="FlashVars" value="' + oEmbed.FlashVars + '" />':'') + '<!-- --></object>';\r
- } else {\r
- oMovie = document.createElement('embed');\r
- for (tmp in oEmbed) {\r
- if (oEmbed.hasOwnProperty(tmp)) {\r
- oMovie.setAttribute(tmp, oEmbed[tmp]);\r
- }\r
- }\r
- }\r
-\r
- _initDebug();\r
-\r
- extraClass = _getSWFCSS();\r
- oTarget = _getDocument();\r
-\r
- if (oTarget) {\r
- _s.oMC = _id(_s.movieID)?_id(_s.movieID):document.createElement('div');\r
- if (!_s.oMC.id) {\r
- _s.oMC.id = _s.movieID;\r
- _s.oMC.className = _s.swfCSS.swfDefault + ' ' + extraClass;\r
- // "hide" flash movie\r
- s = null;\r
- oEl = null;\r
- if (!_s.useFlashBlock) {\r
- if (_s.useHighPerformance) {\r
- s = {\r
- position: 'fixed',\r
- width: '8px',\r
- height: '8px',\r
- // >= 6px for flash to run fast, >= 8px to start up under Firefox/win32 in some cases. odd? yes.\r
- bottom: '0px',\r
- left: '0px',\r
- overflow: 'hidden'\r
- // zIndex:-1 // sit behind everything else - potentially dangerous/buggy?\r
- };\r
- } else {\r
- s = {\r
- position: 'absolute',\r
- width: '6px',\r
- height: '6px',\r
- top: '-9999px',\r
- left: '-9999px'\r
- };\r
- }\r
- }\r
- if (_ua.match(/webkit/i)) {\r
- _s.oMC.style.zIndex = 10000; // soundcloud-reported render/crash fix, safari 5\r
- }\r
-\r
- x = null;\r
- if (!_s.debugFlash) {\r
- for (x in s) {\r
- if (s.hasOwnProperty(x)) {\r
- _s.oMC.style[x] = s[x];\r
- }\r
- }\r
- }\r
- try {\r
- if (!_s.isIE) {\r
- _s.oMC.appendChild(oMovie);\r
- }\r
- oTarget.appendChild(_s.oMC);\r
- if (_s.isIE) {\r
- oEl = _s.oMC.appendChild(document.createElement('div'));\r
- oEl.className = 'sm2-object-box';\r
- oEl.innerHTML = movieHTML;\r
- }\r
- _appendSuccess = true;\r
- } catch(e) {\r
- throw new Error(_str('appXHTML'));\r
- }\r
- _mobileFlash.check();\r
-\r
- } else {\r
- // it's already in the document.\r
- sClass = _s.oMC.className;\r
- _s.oMC.className = (sClass?sClass+' ':_s.swfCSS.swfDefault) + (extraClass?' '+extraClass:'');\r
- _s.oMC.appendChild(oMovie);\r
- if (_s.isIE) {\r
- oEl = _s.oMC.appendChild(document.createElement('div'));\r
- oEl.className = 'sm2-object-box';\r
- oEl.innerHTML = movieHTML;\r
- }\r
- _appendSuccess = true;\r
- _mobileFlash.check(true);\r
-\r
- }\r
- }\r
-\r
- if (specialCase) {\r
- _s._wD(specialCase);\r
- }\r
-\r
- _initMsg();\r
- _s._wD('soundManager::createMovie(): Trying to load ' + smURL + (!this._overHTTP && _s.altURL?' (alternate URL)':''), 1);\r
-\r
- };\r
-\r
- _idCheck = this.getSoundById;\r
-\r
- // <d>\r
- _wDS = function(o, errorLevel) {\r
- if (!o) {\r
- return '';\r
- } else {\r
- return _s._wD(_str(o), errorLevel);\r
- }\r
- };\r
-\r
- if (_wl.indexOf('debug=alert') + 1 && _s.debugMode) {\r
- _s._wD = function(sText) {alert(sText);};\r
- }\r
-\r
- _toggleDebug = function() {\r
- var o = _id(_s.debugID),\r
- oT = _id(_s.debugID + '-toggle');\r
- if (!o) {\r
- return false;\r
- }\r
- if (_debugOpen) {\r
- // minimize\r
- oT.innerHTML = '+';\r
- o.style.display = 'none';\r
- } else {\r
- oT.innerHTML = '-';\r
- o.style.display = 'block';\r
- }\r
- _debugOpen = !_debugOpen;\r
- };\r
-\r
- _debugTS = function(sEventType, bSuccess, sMessage) {\r
- // troubleshooter debug hooks\r
- if (typeof sm2Debugger !== 'undefined') {\r
- try {\r
- sm2Debugger.handleEvent(sEventType, bSuccess, sMessage);\r
- } catch(e) {\r
- // oh well \r
- }\r
- }\r
- };\r
- // </d>\r
-\r
- _mergeObjects = function(oMain, oAdd) {\r
- // non-destructive merge\r
- var o1 = {}, // clone o1\r
- i, o2, o;\r
- for (i in oMain) {\r
- if (oMain.hasOwnProperty(i)) {\r
- o1[i] = oMain[i];\r
- }\r
- }\r
- o2 = (typeof oAdd === 'undefined'?_s.defaultOptions:oAdd);\r
- for (o in o2) {\r
- if (o2.hasOwnProperty(o) && typeof o1[o] === 'undefined') {\r
- o1[o] = o2[o];\r
- }\r
- }\r
- return o1;\r
- };\r
-\r
- _initMovie = function() {\r
- if (_html5Only) {\r
- _createMovie();\r
- return false;\r
- }\r
- // attempt to get, or create, movie\r
- if (_s.o) {\r
- return false; // may already exist\r
- }\r
- _s.o = _s.getMovie(_s.id); // (inline markup)\r
- if (!_s.o) {\r
- if (!_oRemoved) {\r
- // try to create\r
- _createMovie(_s.id, _s.url);\r
- } else {\r
- // try to re-append removed movie after reboot()\r
- if (!_s.isIE) {\r
- _s.oMC.appendChild(_oRemoved);\r
- } else {\r
- _s.oMC.innerHTML = _oRemovedHTML;\r
- }\r
- _oRemoved = null;\r
- _didAppend = true;\r
- }\r
- _s.o = _s.getMovie(_s.id);\r
- }\r
- if (_s.o) {\r
- _s._wD('soundManager::initMovie(): Got '+_s.o.nodeName+' element ('+(_didAppend?'created via JS':'static HTML')+')');\r
- _wDS('waitEI');\r
- }\r
- if (typeof _s.oninitmovie === 'function') {\r
- setTimeout(_s.oninitmovie, 1);\r
- }\r
- };\r
-\r
- _go = function(sURL) {\r
- // where it all begins.\r
- if (sURL) {\r
- _s.url = sURL;\r
- }\r
- _initMovie();\r
- };\r
-\r
- _waitForEI = function() {\r
- if (_waitingForEI) {\r
- return false;\r
- }\r
- _waitingForEI = true;\r
- if (_tryInitOnFocus && !_isFocused) {\r
- _wDS('waitFocus');\r
- return false;\r
- }\r
- var p;\r
- if (!_didInit) {\r
- p = _s.getMoviePercent();\r
- _s._wD(_str('waitImpatient', (p === 100?' (SWF loaded)':(p > 0?' (SWF ' + p + '% loaded)':''))));\r
- }\r
- setTimeout(function() {\r
- p = _s.getMoviePercent();\r
- if (!_didInit) {\r
- _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);\r
- if (!this._overHTTP && p) {\r
- _wDS('localFail', 2);\r
- if (!_s.debugFlash) {\r
- _wDS('tryDebug', 2);\r
- }\r
- }\r
- if (p === 0) {\r
- // if 0 (not null), probably a 404.\r
- _s._wD(_str('swf404', _s.url));\r
- }\r
- _debugTS('flashtojs', false, ': Timed out' + this._overHTTP?' (Check flash security or flash blockers)':' (No plugin/missing SWF?)');\r
- }\r
- // give up / time-out, depending\r
- if (!_didInit && _okToDisable) {\r
- if (p === null) {\r
- // SWF failed. Maybe blocked.\r
- if (_s.useFlashBlock || _s.flashLoadTimeout === 0) {\r
- if (_s.useFlashBlock) {\r
- _flashBlockHandler();\r
- }\r
- _wDS('waitForever');\r
- } else {\r
- // old SM2 behaviour, simply fail\r
- _failSafely(true);\r
- }\r
- } else {\r
- // flash loaded? Shouldn't be a blocking issue, then.\r
- if (_s.flashLoadTimeout === 0) {\r
- _wDS('waitForever');\r
- } else {\r
- _failSafely(true);\r
- }\r
- }\r
- }\r
- }, _s.flashLoadTimeout);\r
- };\r
-\r
- _getSWFCSS = function() {\r
- var css = [];\r
- if (_s.debugMode) {\r
- css.push(_s.swfCSS.sm2Debug);\r
- }\r
- if (_s.debugFlash) {\r
- css.push(_s.swfCSS.flashDebug);\r
- }\r
- if (_s.useHighPerformance) {\r
- css.push(_s.swfCSS.highPerf);\r
- }\r
- return css.join(' ');\r
- };\r
-\r
- _flashBlockHandler = function() {\r
- // *possible* flash block situation.\r
- var name = 'soundManager::flashBlockHandler()', p = _s.getMoviePercent();\r
- if (!_s.supported()) {\r
- if (_needsFlash) {\r
- // make the movie more visible, so user can fix\r
- _s.oMC.className = _getSWFCSS() + ' ' + _s.swfCSS.swfDefault + ' ' + (p === null?_s.swfCSS.swfTimedout:_s.swfCSS.swfError);\r
- _s._wD(name+': '+_str('fbTimeout')+(p?' ('+_str('fbLoaded')+')':''));\r
- }\r
- _s.didFlashBlock = true;\r
- _processOnReady(true); // fire onready(), complain lightly\r
- // onerror?\r
- if (_s.onerror instanceof Function) {\r
- _s.onerror.apply(window);\r
- }\r
- } else {\r
- // SM2 loaded OK (or recovered)\r
- if (_s.didFlashBlock) {\r
- _s._wD(name+': Unblocked');\r
- }\r
- if (_s.oMC) {\r
- _s.oMC.className = _getSWFCSS() + ' ' + _s.swfCSS.swfDefault + (' '+_s.swfCSS.swfUnblocked);\r
- }\r
- }\r
- };\r
-\r
- _handleFocus = function() {\r
- if (_isFocused || !_tryInitOnFocus) {\r
- return true;\r
- }\r
- _okToDisable = true;\r
- _isFocused = true;\r
- _s._wD('soundManager::handleFocus()');\r
- if (_tryInitOnFocus) {\r
- // giant Safari 3.1 hack - assume window in focus if mouse is moving, since document.hasFocus() not currently implemented.\r
- window.removeEventListener('mousemove', _handleFocus, false);\r
- }\r
- // allow init to restart\r
- _waitingForEI = false;\r
- setTimeout(_waitForEI, 500);\r
- // detach event\r
- if (window.removeEventListener) {\r
- window.removeEventListener('focus', _handleFocus, false);\r
- } else if (window.detachEvent) {\r
- window.detachEvent('onfocus', _handleFocus);\r
- }\r
- };\r
-\r
- _initComplete = function(bNoDisable) {\r
- if (_didInit) {\r
- return false;\r
- }\r
- if (_html5Only) {\r
- // all good.\r
- _s._wD('-- SoundManager 2: loaded --');\r
- _didInit = true;\r
- _processOnReady();\r
- _initUserOnload();\r
- return true;\r
- }\r
- var sClass = _s.oMC.className,\r
- wasTimeout = (_s.useFlashBlock && _s.flashLoadTimeout && !_s.getMoviePercent());\r
- if (!wasTimeout) {\r
- _didInit = true;\r
- }\r
- _s._wD('-- SoundManager 2 ' + (_disabled?'failed to load':'loaded') + ' (' + (_disabled?'security/load error':'OK') + ') --', 1);\r
- if (_disabled || bNoDisable) {\r
- if (_s.useFlashBlock) {\r
- _s.oMC.className = _getSWFCSS() + ' ' + (_s.getMoviePercent() === null?_s.swfCSS.swfTimedout:_s.swfCSS.swfError);\r
- }\r
- _processOnReady();\r
- _debugTS('onload', false);\r
- if (_s.onerror instanceof Function) {\r
- _s.onerror.apply(window);\r
- }\r
- return false;\r
- } else {\r
- _debugTS('onload', true);\r
- }\r
- if (_s.waitForWindowLoad && !_windowLoaded) {\r
- _wDS('waitOnload');\r
- if (window.addEventListener) {\r
- window.addEventListener('load', _initUserOnload, false);\r
- } else if (window.attachEvent) {\r
- window.attachEvent('onload', _initUserOnload);\r
- }\r
- return false;\r
- } else {\r
- if (_s.waitForWindowLoad && _windowLoaded) {\r
- _wDS('docLoaded');\r
- }\r
- _initUserOnload();\r
- }\r
- };\r
-\r
- _addOnReady = function(oMethod, oScope) {\r
- _onready.push({\r
- 'method': oMethod,\r
- 'scope': (oScope || null),\r
- 'fired': false\r
- });\r
- };\r
-\r
- _processOnReady = function(ignoreInit) {\r
- if (!_didInit && !ignoreInit) {\r
- // not ready yet.\r
- return false;\r
- }\r
- var status = {\r
- success: (ignoreInit?_s.supported():!_disabled)\r
- },\r
- queue = [], i, j,\r
- canRetry = (!_s.useFlashBlock || (_s.useFlashBlock && !_s.supported()));\r
- for (i = 0, j = _onready.length; i < j; i++) {\r
- if (_onready[i].fired !== true) {\r
- queue.push(_onready[i]);\r
- }\r
- }\r
- if (queue.length) {\r
- _s._wD(_sm + ': Firing ' + queue.length + ' onready() item' + (queue.length > 1?'s':''));\r
- for (i = 0, j = queue.length; i < j; i++) {\r
- if (queue[i].scope) {\r
- queue[i].method.apply(queue[i].scope, [status]);\r
- } else {\r
- queue[i].method(status);\r
- }\r
- if (!canRetry) { // flashblock case doesn't count here\r
- queue[i].fired = true;\r
- }\r
- }\r
- }\r
- };\r
-\r
- _initUserOnload = function() {\r
- window.setTimeout(function() {\r
- if (_s.useFlashBlock) {\r
- _flashBlockHandler();\r
- }\r
- _processOnReady();\r
- _wDS('onload', 1);\r
- // call user-defined "onload", scoped to window\r
- _s.onload.apply(window);\r
- _wDS('onloadOK', 1);\r
- },1);\r
- };\r
-\r
- _featureCheck = function() {\r
- var needsFlash, item,\r
- isBadSafari = (!_wl.match(/usehtml5audio/i) && !_wl.match(/sm2\-ignorebadua/i) && _s.isSafari && _ua.match(/OS X 10_6_(3|4)/i) && _ua.match(/(531\.22\.7|533\.16|533\.17\.8)/i)), // Safari 4.0.5 (531.22.7), 5.0 (533.16), and 5.1 (533.17.8) have buggy/broken HTML5 audio on Snow Leopard. :/ Known Apple "radar" bug. https://bugs.webkit.org/show_bug.cgi?id=32159\r
- isSpecial = (_ua.match(/iphone os (1|2|3_0|3_1)/i)?true:false); // iPhone <= 3.1 has broken HTML5 audio(), but firmware 3.2 (iPad) + iOS4 works.\r
- if (isSpecial) {\r
- _s.hasHTML5 = false; // has Audio(), but is broken; let it load links directly.\r
- _html5Only = true; // ignore flash case, however\r
- if (_s.oMC) {\r
- _s.oMC.style.display = 'none';\r
- }\r
- return false;\r
- }\r
- if (_s.useHTML5Audio) {\r
- if (!_s.html5 || !_s.html5.canPlayType) {\r
- _s._wD('SoundManager: No HTML5 Audio() support detected.');\r
- _s.hasHTML5 = false;\r
- return true;\r
- } else {\r
- _s.hasHTML5 = true;\r
- }\r
- if (isBadSafari) {\r
- _s._wD('SoundManager::Note: Buggy HTML5 Audio in this specific browser + OS, see https://bugs.webkit.org/show_bug.cgi?id=32159 - disabling HTML5',1);\r
- _s.useHTML5Audio = false;\r
- _s.hasHTML5 = false;\r
- return true;\r
- }\r
- } else {\r
- // flash required.\r
- return true;\r
- }\r
- for (item in _s.audioFormats) {\r
- if (_s.audioFormats.hasOwnProperty(item)) {\r
- if (_s.audioFormats[item].required && !_s.html5.canPlayType(_s.audioFormats[item].type)) {\r
- // may need flash for this format?\r
- needsFlash = true;\r
- }\r
- }\r
- }\r
- // sanity check..\r
- if (_s.ignoreFlash) {\r
- needsFlash = false;\r
- }\r
- _html5Only = (_s.useHTML5Audio && _s.hasHTML5 && !needsFlash);\r
- return needsFlash;\r
- };\r
-\r
- _init = function() {\r
- var item, tests = [];\r
- _wDS('init');\r
- // called after onload()\r
-\r
- if (_didInit) {\r
- _wDS('didInit');\r
- return false;\r
- }\r
-\r
- function _cleanup() {\r
- if (window.removeEventListener) {\r
- window.removeEventListener('load', _s.beginDelayedInit, false);\r
- } else if (window.detachEvent) {\r
- window.detachEvent('onload', _s.beginDelayedInit);\r
- }\r
- }\r
-\r
- if (_s.hasHTML5) {\r
- for (item in _s.audioFormats) {\r
- if (_s.audioFormats.hasOwnProperty(item)) {\r
- tests.push(item+': '+_s.html5[item]);\r
- }\r
- }\r
- _s._wD('-- SoundManager 2: HTML5 support tests ('+_s.html5Test+'): '+tests.join(', ')+' --',1);\r
- }\r
-\r
- if (_html5Only) {\r
- if (!_didInit) {\r
- // we don't need no steenking flash!\r
- _cleanup();\r
- _s.enabled = true;\r
- _initComplete();\r
- }\r
- return true;\r
- } else {\r
-}\r
-\r
- // flash path\r
- _initMovie();\r
- try {\r
- _wDS('flashJS');\r
- _s.o._externalInterfaceTest(false); // attempt to talk to Flash\r
- if (!_s.allowPolling) {\r
- _wDS('noPolling', 1);\r
- } else {\r
- _setPolling(true, _s.useFastPolling?true:false);\r
- }\r
- if (!_s.debugMode) {\r
- _s.o._disableDebug();\r
- }\r
- _s.enabled = true;\r
- _debugTS('jstoflash', true);\r
- } catch(e) {\r
- _s._wD('js/flash exception: ' + e.toString());\r
- _debugTS('jstoflash', false);\r
- _failSafely(true); // don't disable, for reboot()\r
- _initComplete();\r
- return false;\r
- }\r
- _initComplete();\r
- // event cleanup\r
- _cleanup();\r
- };\r
-\r
- _beginInit = function() {\r
- if (_initPending) {\r
- return false;\r
- }\r
- _createMovie();\r
- _initMovie();\r
- _initPending = true;\r
- return true;\r
- };\r
-\r
- _dcLoaded = function() {\r
- if (_didDCLoaded) {\r
- return false;\r
- }\r
- _didDCLoaded = true;\r
- _initDebug();\r
- _testHTML5();\r
- _s.html5.usingFlash = _featureCheck();\r
- _needsFlash = _s.html5.usingFlash;\r
- _didDCLoaded = true;\r
- _go();\r
- };\r
-\r
- _startTimer = function(oSound) {\r
- if (!oSound._hasTimer) {\r
- oSound._hasTimer = true;\r
- }\r
- };\r
-\r
- _stopTimer = function(oSound) {\r
- if (oSound._hasTimer) {\r
- oSound._hasTimer = false;\r
- }\r
- };\r
-\r
- // "private" methods called by Flash\r
-\r
- this._setSandboxType = function(sandboxType) {\r
- var sb = _s.sandbox;\r
- sb.type = sandboxType;\r
- sb.description = sb.types[(typeof sb.types[sandboxType] !== 'undefined'?sandboxType:'unknown')];\r
- _s._wD('Flash security sandbox type: ' + sb.type);\r
- if (sb.type === 'localWithFile') {\r
- sb.noRemote = true;\r
- sb.noLocal = false;\r
- _wDS('secNote', 2);\r
- } else if (sb.type === 'localWithNetwork') {\r
- sb.noRemote = false;\r
- sb.noLocal = true;\r
- } else if (sb.type === 'localTrusted') {\r
- sb.noRemote = false;\r
- sb.noLocal = false;\r
- }\r
- };\r
-\r
- this._externalInterfaceOK = function(flashDate) {\r
- // callback from flash for confirming that movie loaded, EI is working etc.\r
- // flashDate = approx. timing/delay info for JS/flash bridge\r
- if (_s.swfLoaded) {\r
- return false;\r
- }\r
- var eiTime = new Date().getTime();\r
- _s._wD('soundManager::externalInterfaceOK()' + (flashDate?' (~' + (eiTime - flashDate) + ' ms)':''));\r
- _debugTS('swf', true);\r
- _debugTS('flashtojs', true);\r
- _s.swfLoaded = true;\r
- _tryInitOnFocus = false;\r
- if (_s.isIE) {\r
- // IE needs a timeout OR delay until window.onload - may need TODO: investigating\r
- setTimeout(_init, 100);\r
- } else {\r
- _init();\r
- }\r
- };\r
-\r
- this._onfullscreenchange = function(bFullScreen) {\r
- _s._wD('onfullscreenchange(): ' + bFullScreen);\r
- _s.isFullScreen = (bFullScreen === 1?true:false);\r
- if (!_s.isFullScreen) {\r
- // attempt to restore window focus after leaving full-screen\r
- try {\r
- window.focus();\r
- _s._wD('window.focus()');\r
- } catch(e) {\r
- // oh well\r
- }\r
- }\r
- };\r
-\r
- // --- SMSound (sound object) instance ---\r
-\r
- SMSound = function(oOptions) {\r
- var _t = this, _resetProperties, _add_html5_events, _stop_html5_timer, _start_html5_timer, _get_html5_duration, _a;\r
- this.sID = oOptions.id;\r
- this.url = oOptions.url;\r
- this.options = _mergeObjects(oOptions);\r
- this.instanceOptions = this.options; // per-play-instance-specific options\r
- this._iO = this.instanceOptions; // short alias\r
- // assign property defaults (volume, pan etc.)\r
- this.pan = this.options.pan;\r
- this.volume = this.options.volume;\r
- // this.autoPlay = oOptions.autoPlay ? oOptions.autoPlay : false;\r
- this._lastURL = null;\r
- this.isHTML5 = false;\r
-\r
- // --- public methods ---\r
-\r
- this.id3 = {\r
- /* \r
- Name/value pairs eg. this.id3.songname set via Flash when available - download docs for reference\r
- http://livedocs.macromedia.com/flash/8/\r
- */\r
- };\r
-\r
- this._debug = function() {\r
- // <d>\r
- // pseudo-private console.log()-style output\r
- if (_s.debugMode) {\r
- var stuff = null, msg = [], sF, sfBracket, maxLength = 64;\r
- for (stuff in _t.options) {\r
- if (_t.options[stuff] !== null) {\r
- if (_t.options[stuff] instanceof Function) {\r
- // handle functions specially\r
- sF = _t.options[stuff].toString();\r
- sF = sF.replace(/\s\s+/g, ' '); // normalize spaces\r
- sfBracket = sF.indexOf('{');\r
- msg.push(' ' + stuff + ': {' + sF.substr(sfBracket + 1, (Math.min(Math.max(sF.indexOf('\n') - 1, maxLength), maxLength))).replace(/\n/g, '') + '... }');\r
- } else {\r
- msg.push(' ' + stuff + ': ' + _t.options[stuff]);\r
- }\r
- }\r
- }\r
- _s._wD('SMSound() merged options: {\n' + msg.join(', \n') + '\n}');\r
- }\r
- // </d>\r
- };\r
-\r
- this._debug();\r
-\r
- this.load = function(oOptions) {\r
- var oS = null;\r
- if (typeof oOptions !== 'undefined') {\r
- _t._iO = _mergeObjects(oOptions);\r
- _t.instanceOptions = _t._iO;\r
- } else {\r
- oOptions = _t.options;\r
- _t._iO = oOptions;\r
- _t.instanceOptions = _t._iO;\r
- if (_t._lastURL && _t._lastURL !== _t.url) {\r
- _wDS('manURL');\r
- _t._iO.url = _t.url;\r
- _t.url = null;\r
- }\r
- }\r
- _s._wD('soundManager.load(): ' + _t._iO.url, 1);\r
- if (_t._iO.url === _t.url && _t.readyState !== 0 && _t.readyState !== 2) {\r
- _wDS('onURL', 1);\r
- return _t;\r
- }\r
- _t._lastURL = _t.url;\r
- _t.loaded = false;\r
- _t.readyState = 1;\r
- _t.playState = 0; // (oOptions.autoPlay?1:0); // if autoPlay, assume "playing" is true (no way to detect when it actually starts in Flash unless onPlay is watched?)\r
- if (_html5OK(_t._iO)) {\r
- _s._wD('HTML 5 load: '+_t._iO.url);\r
- oS = _t._setup_html5(_t._iO);\r
- oS.load();\r
- if (_t._iO.autoPlay) {\r
- _t.play();\r
- }\r
- } else {\r
- try {\r
- _t.isHTML5 = false;\r
- _t._iO = _loopFix(_t._iO);\r
- if (_fV === 8) {\r
- _s.o._load(_t.sID, _t._iO.url, _t._iO.stream, _t._iO.autoPlay, (_t._iO.whileloading?1:0), _t._iO.loops||1);\r
- } else {\r
- _s.o._load(_t.sID, _t._iO.url, _t._iO.stream?true:false, _t._iO.autoPlay?true:false, _t._iO.loops||1); // ,(_tO.whileloading?true:false)\r
- if (_t._iO.isMovieStar && _t._iO.autoLoad && !_t._iO.autoPlay) {\r
- // special case: MPEG4 content must start playing to load, then pause to prevent playing.\r
- _t.pause();\r
- }\r
- }\r
- } catch(e) {\r
- _wDS('smError', 2);\r
- _debugTS('onload', false);\r
- _s.onerror();\r
- _s.disable();\r
- }\r
- }\r
- return _t;\r
- };\r
-\r
- this.unload = function() {\r
- // Flash 8/AS2 can't "close" a stream - fake it by loading an empty MP3\r
- // Flash 9/AS3: Close stream, preventing further load\r
- if (_t.readyState !== 0) {\r
- _s._wD('SMSound.unload(): "' + _t.sID + '"');\r
- if (_t.readyState !== 2) { // reset if not error\r
- _t.setPosition(0, true); // reset current sound positioning\r
- }\r
- if (!_t.isHTML5) {\r
- if (_fV === 8) {\r
- _s.o._unload(_t.sID, _s.nullURL);\r
- } else {\r
- _t.setAutoPlay(false); // ?\r
- _s.o._unload(_t.sID);\r
- }\r
- } else {\r
- _stop_html5_timer();\r
- if (_a) {\r
- // abort()-style method here, stop loading? (doesn't exist?)\r
- _a.pause();\r
- _a.src = _s.nullURL; // needed? does nulling object work? any better way to cancel/unload/abort?\r
- _a.load();\r
- _t._audio = null;\r
- _a = null;\r
- // delete _t._audio;\r
- }\r
- } \r
- // reset load/status flags\r
- _resetProperties();\r
- }\r
- return _t;\r
- };\r
-\r
- this.destruct = function() {\r
- _s._wD('SMSound.destruct(): "' + _t.sID + '"');\r
- if (!_t.isHTML5) {\r
- // kill sound within Flash\r
- // Disable the onfailure handler\r
- _t._iO.onfailure = null;\r
- _s.o._destroySound(_t.sID);\r
- } else {\r
- _stop_html5_timer();\r
- if (_a) {\r
- _a.pause();\r
- _a.src = 'about:blank';\r
- _a.load();\r
- _t._audio = null;\r
- _a = null;\r
- // delete _t._audio;\r
- }\r
- }\r
- _s.destroySound(_t.sID, true); // ensure deletion from controller\r
- };\r
-\r
- this.play = function(oOptions) {\r
- var fN = 'SMSound.play(): ', allowMulti;\r
- if (!oOptions) {\r
- oOptions = {};\r
- }\r
- _t._iO = _mergeObjects(oOptions, _t._iO);\r
- _t._iO = _mergeObjects(_t._iO, _t.options);\r
- _t.instanceOptions = _t._iO;\r
- if (_t._iO.serverURL) {\r
- if (!_t.connected) {\r
- _s._wD(fN+' Netstream not connected yet - setting autoPlay');\r
- _t.setAutoPlay(true);\r
- return _t;\r
- }\r
- }\r
- if (_html5OK(_t._iO)) {\r
- _t._setup_html5(_t._iO);\r
- _start_html5_timer();\r
- }\r
- if (_t.playState === 1) {\r
- allowMulti = _t._iO.multiShot;\r
- if (!allowMulti) {\r
- _s._wD(fN + '"' + _t.sID + '" already playing (one-shot)', 1);\r
- return _t;\r
- } else {\r
- _s._wD(fN + '"' + _t.sID + '" already playing (multi-shot)', 1);\r
- if (_t.isHTML5) {\r
- // TODO: BUG?\r
- _t.setPosition(_t._iO.position);\r
- }\r
- }\r
- }\r
- if (!_t.loaded) {\r
- if (_t.readyState === 0) {\r
- _s._wD(fN + 'Attempting to load "' + _t.sID + '"', 1);\r
- // try to get this sound playing ASAP\r
- //_t._iO.stream = true; // breaks stream=false case?\r
- if (!_t.isHTML5) {\r
- // HTML5 double-play bug otherwise.\r
- if (!_t._iO.serverURL) {\r
- _t._iO.autoPlay = true;\r
- _t.load(_t._iO);\r
- }\r
- } else {\r
- _t.load(_t._iO);\r
- _t.readyState = 1;\r
- }\r
- } else if (_t.readyState === 2) {\r
- _s._wD(fN + 'Could not load "' + _t.sID + '" - exiting', 2);\r
- return _t;\r
- } else {\r
- _s._wD(fN + '"' + _t.sID + '" is loading - attempting to play..', 1);\r
- }\r
- } else {\r
- _s._wD(fN + '"' + _t.sID + '"');\r
- }\r
- if (_t.paused && _t.position !== null) { // https://gist.github.com/37b17df75cc4d7a90bf6\r
- _s._wD(fN + '"' + _t.sID + '" is resuming from paused state',1);\r
- _t.resume();\r
- } else {\r
- _s._wD(fN+'"'+ _t.sID+'" is starting to play');\r
- _t.playState = 1;\r
- _t.paused = false; // https://gist.github.com/859638f341b25669b587\r
- if (!_t.instanceCount || (_fV > 8 && !_t.isHTML5)) {\r
- _t.instanceCount++;\r
- }\r
- _t.position = (typeof _t._iO.position !== 'undefined' && !isNaN(_t._iO.position)?_t._iO.position:0);\r
- _t._iO = _loopFix(_t._iO);\r
- if (_t._iO.onplay) {\r
- _t._iO.onplay.apply(_t);\r
- }\r
- _t.setVolume(_t._iO.volume, true); // restrict volume to instance options only\r
- _t.setPan(_t._iO.pan, true);\r
- if (!_t.isHTML5) {\r
- if (_fV === 9 && _t._iO.serverURL) {\r
- // autoPlay for RTMP case\r
- _t.setAutoPlay(true);\r
- }\r
- _s.o._start(_t.sID, _t._iO.loops || 1, (_fV === 9?_t.position:_t.position / 1000));\r
- } else {\r
- _start_html5_timer();\r
- _t._setup_html5().play();\r
- }\r
- }\r
- return _t;\r
- };\r
-\r
- this.start = this.play; // just for convenience\r
-\r
- this.stop = function(bAll) {\r
- if (_t.playState === 1) {\r
- _t._onbufferchange(0);\r
- _t.resetOnPosition(0);\r
- if (!_t.isHTML5) {\r
- _t.playState = 0;\r
- }\r
- _t.paused = false;\r
- if (_t._iO.onstop) {\r
- _t._iO.onstop.apply(_t);\r
- }\r
- if (!_t.isHTML5) {\r
- _s.o._stop(_t.sID, bAll);\r
- // hack for netStream: just unload\r
- if (_t._iO.serverURL) {\r
- _t.unload();\r
- }\r
- } else {\r
- if (_a) {\r
- _t.setPosition(0); // act like Flash, though\r
- _a.pause(); // html5 has no stop()\r
- _t.playState = 0;\r
- _t._onTimer(); // and update UI\r
- _stop_html5_timer();\r
- _t.unload();\r
- }\r
- }\r
- _t.instanceCount = 0;\r
- _t._iO = {};\r
- // _t.instanceOptions = _t._iO;\r
- }\r
- return _t;\r
- };\r
-\r
- this.setAutoPlay = function(autoPlay) {\r
- // _s._wD('setAutoPlay('+autoPlay+')');\r
- _t._iO.autoPlay = autoPlay;\r
- _s.o._setAutoPlay(_t.sID, autoPlay);\r
- if (autoPlay) {\r
- // _t.playState = 1; // ?\r
- if (!_t.instanceCount) {\r
- _t.instanceCount++;\r
- }\r
- }\r
- };\r
-\r
- this.setPosition = function(nMsecOffset, bNoDebug) {\r
- if (typeof nMsecOffset === 'undefined') {\r
- nMsecOffset = 0;\r
- }\r
- var offset = (_t.isHTML5 ? Math.max(nMsecOffset,0) : Math.min(_t.duration, Math.max(nMsecOffset, 0))); // position >= 0 and <= current available (loaded) duration\r
- _t._iO.position = offset;\r
- _t.resetOnPosition(_t._iO.position);\r
- if (!_t.isHTML5) {\r
- _s.o._setPosition(_t.sID, (_fV === 9?_t._iO.position:_t._iO.position / 1000), (_t.paused || !_t.playState)); // if paused or not playing, will not resume (by playing)\r
- } else if (_a) {\r
- _s._wD('setPosition(): setting position to '+(_t._iO.position / 1000));\r
- if (_t.playState) {\r
- // DOM/JS errors/exceptions to watch out for:\r
- // if seek is beyond (loaded?) position, "DOM exception 11"\r
- // "INDEX_SIZE_ERR": DOM exception 1\r
- try {\r
- _a.currentTime = _t._iO.position / 1000;\r
- } catch(e) {\r
- _s._wD('setPosition('+_t._iO.position+'): WARN: Caught exception: '+e.message, 2);\r
- }\r
- } else {\r
- _s._wD('HTML 5 warning: cannot set position while playState == 0 (not playing)',2);\r
- }\r
- if (_t.paused) { // if paused, refresh UI right away\r
- _t._onTimer(true); // force update\r
- // TODO: resume for movieStar only?\r
- if (_t._iO.useMovieStar) {\r
- _t.resume();\r
- }\r
- }\r
- }\r
- return _t;\r
- };\r
-\r
- this.pause = function(bCallFlash) {\r
- // if (_t.paused || _t.playState === 0) {\r
- if (_t.paused || (_t.playState === 0 && _t.readyState !== 1)) { // TODO: Verify vs. old\r
- return _t;\r
- }\r
- _s._wD('SMSound.pause()');\r
- _t.paused = true;\r
- if (!_t.isHTML5) {\r
- if (bCallFlash || bCallFlash === undefined) {\r
- _s.o._pause(_t.sID);\r
- }\r
- } else {\r
- _t._setup_html5().pause();\r
- _stop_html5_timer();\r
- }\r
- if (_t._iO.onpause) {\r
- _t._iO.onpause.apply(_t);\r
- }\r
- return _t;\r
- };\r
-\r
- this.resume = function() {\r
- if (!_t.paused || _t.playState === 0) {\r
- return _t;\r
- }\r
- _s._wD('SMSound.resume()');\r
- _t.paused = false;\r
- _t.playState = 1; // TODO: verify that this is needed.\r
- if (!_t.isHTML5) {\r
- _s.o._pause(_t.sID); // flash method is toggle-based (pause/resume)\r
- } else {\r
- _t._setup_html5().play();\r
- _start_html5_timer();\r
- }\r
- if (_t._iO.onresume) {\r
- _t._iO.onresume.apply(_t);\r
- }\r
- return _t;\r
- };\r
-\r
- this.togglePause = function() {\r
- _s._wD('SMSound.togglePause()');\r
- if (_t.playState === 0) {\r
- _t.play({\r
- position: (_fV === 9 && !_t.isHTML5 ? _t.position:_t.position / 1000)\r
- });\r
- return _t;\r
- }\r
- if (_t.paused) {\r
- _t.resume();\r
- } else {\r
- _t.pause();\r
- }\r
- return _t;\r
- };\r
-\r
- this.setPan = function(nPan, bInstanceOnly) {\r
- if (typeof nPan === 'undefined') {\r
- nPan = 0;\r
- }\r
- if (typeof bInstanceOnly === 'undefined') {\r
- bInstanceOnly = false;\r
- }\r
- if (!_t.isHTML5) {\r
- _s.o._setPan(_t.sID, nPan);\r
- } else {\r
- // no HTML 5 pan?\r
- }\r
- _t._iO.pan = nPan;\r
- if (!bInstanceOnly) {\r
- _t.pan = nPan;\r
- }\r
- return _t;\r
- };\r
-\r
- this.setVolume = function(nVol, bInstanceOnly) {\r
- if (typeof nVol === 'undefined') {\r
- nVol = 100;\r
- }\r
- if (typeof bInstanceOnly === 'undefined') {\r
- bInstanceOnly = false;\r
- }\r
- if (!_t.isHTML5) {\r
- _s.o._setVolume(_t.sID, (_s.muted && !_t.muted) || _t.muted?0:nVol);\r
- } else if (_a) {\r
- _a.volume = nVol/100;\r
- } \r
- _t._iO.volume = nVol;\r
- if (!bInstanceOnly) {\r
- _t.volume = nVol;\r
- }\r
- return _t;\r
- };\r
-\r
- this.mute = function() {\r
- _t.muted = true;\r
- if (!_t.isHTML5) {\r
- _s.o._setVolume(_t.sID, 0);\r
- } else if (_a) {\r
- _a.muted = true;\r
- }\r
- return _t;\r
- };\r
-\r
- this.unmute = function() {\r
- _t.muted = false;\r
- var hasIO = typeof _t._iO.volume !== 'undefined';\r
- if (!_t.isHTML5) {\r
- _s.o._setVolume(_t.sID, hasIO?_t._iO.volume:_t.options.volume);\r
- } else if (_a) {\r
- _a.muted = false;\r
- }\r
- return _t;\r
- };\r
-\r
- this.toggleMute = function() {\r
- return (_t.muted?_t.unmute():_t.mute());\r
- };\r
-\r
- this.onposition = function(nPosition, oMethod, oScope) {\r
- // todo: allow for ranges, too? eg. (nPosition instanceof Array)\r
- _t._onPositionItems.push({\r
- position: nPosition,\r
- method: oMethod,\r
- scope: (typeof oScope !== 'undefined'?oScope:_t),\r
- fired: false\r
- });\r
- return _t;\r
- };\r
-\r
- this.processOnPosition = function() {\r
- // sound currently playing?\r
- var i, item, j = _t._onPositionItems.length;\r
- if (!j || !_t.playState || _t._onPositionFired >= j) {\r
- return false;\r
- }\r
- for (i=j; i--;) {\r
- item = _t._onPositionItems[i];\r
- if (!item.fired && _t.position >= item.position) {\r
- item.method.apply(item.scope,[item.position]);\r
- item.fired = true;\r
- _s._onPositionFired++;\r
- }\r
- }\r
- };\r
-\r
- this.resetOnPosition = function(nPosition) {\r
- // reset "fired" for items interested in this position\r
- var i, item, j = _t._onPositionItems.length;\r
- if (!j) {\r
- return false;\r
- }\r
- for (i=j; i--;) {\r
- item = _t._onPositionItems[i];\r
- if (item.fired && nPosition <= item.position) {\r
- item.fired = false;\r
- _s._onPositionFired--;\r
- }\r
- }\r
- };\r
-\r
- // pseudo-private soundManager reference\r
-\r
- this._onTimer = function(bForce) {\r
- // HTML 5-only _whileplaying() etc.\r
- if (_t._hasTimer || bForce) {\r
- var time;\r
- if (_a && (bForce || ((_t.playState > 0 || _t.readyState === 1) && !_t.paused))) { // TODO: May not need to track readyState (1 = loading)\r
- _t.duration = _get_html5_duration();\r
- _t.durationEstimate = _t.duration;\r
- time = _a.currentTime?_a.currentTime*1000:0;\r
- _t._whileplaying(time,{},{},{},{});\r
- return true;\r
- } else {\r
- // beta testing\r
- _s._wD('_onTimer: Warn for "'+_t.sID+'": '+(!_a?'Could not find element. ':'')+(_t.playState === 0?'playState bad, 0?':'playState = '+_t.playState+', OK'));\r
- return false;\r
- }\r
- }\r
- };\r
-\r
- // --- private internals ---\r
-\r
- _get_html5_duration = function() {\r
- var d = (_a?_a.duration*1000:undefined);\r
- if (d) {\r
- return (!isNaN(d)?d:null);\r
- }\r
- };\r
-\r
- _start_html5_timer = function() {\r
- if (_t.isHTML5) {\r
- _startTimer(_t);\r
- }\r
- };\r
-\r
- _stop_html5_timer = function() {\r
- if (_t.isHTML5) {\r
- _stopTimer(_t);\r
- }\r
- };\r
-\r
- _resetProperties = function(bLoaded) {\r
- _t._onPositionItems = [];\r
- _t._onPositionFired = 0;\r
- _t._hasTimer = null;\r
- _t._added_events = null;\r
- _t._audio = null;\r
- _a = null;\r
- _t.bytesLoaded = null;\r
- _t.bytesTotal = null;\r
- _t.position = null;\r
- _t.duration = null;\r
- _t.durationEstimate = null;\r
- _t.failures = 0;\r
- _t.loaded = false;\r
- _t.playState = 0;\r
- _t.paused = false;\r
- _t.readyState = 0; // 0 = uninitialised, 1 = loading, 2 = failed/error, 3 = loaded/success\r
- _t.muted = false;\r
- _t.didBeforeFinish = false;\r
- _t.didJustBeforeFinish = false;\r
- _t.isBuffering = false;\r
- _t.instanceOptions = {};\r
- _t.instanceCount = 0;\r
- _t.peakData = {\r
- left: 0,\r
- right: 0\r
- };\r
- _t.waveformData = {\r
- left: [],\r
- right: []\r
- };\r
- _t.eqData = [];\r
- // dirty hack for now: also have left/right arrays off this, maintain compatibility\r
- _t.eqData.left = [];\r
- _t.eqData.right = [];\r
- };\r
-\r
- _resetProperties();\r
-\r
- // pseudo-private methods used by soundManager\r
-\r
- this._setup_html5 = function(oOptions) {\r
- var _iO = _mergeObjects(_t._iO, oOptions);\r
- if (_a) {\r
- if (_t.url !== _iO.url) {\r
- _s._wD('setting new URL on existing object: '+_iO.url);\r
- _a.src = _iO.url;\r
- }\r
- } else {\r
- _s._wD('creating HTML 5 audio element with URL: '+_iO.url);\r
- _t._audio = new Audio(_iO.url);\r
- _a = _t._audio;\r
- _t.isHTML5 = true;\r
- _add_html5_events();\r
- }\r
- _a.loop = (_iO.loops>1?'loop':'');\r
- return _t._audio;\r
- };\r
-\r
- // related private methods\r
-\r
- _add_html5_events = function() {\r
- if (_t._added_events) {\r
- return false;\r
- }\r
- _t._added_events = true;\r
-\r
- function _add(oEvt, oFn, bBubble) {\r
- return (_a ? _a.addEventListener(oEvt, oFn, bBubble||false) : null);\r
- }\r
-\r
- _add('load', function(e) {\r
- _s._wD('HTML5::load: '+_t.sID);\r
- if (_a) {\r
- _t._onbufferchange(0);\r
- _t._whileloading(_t.bytesTotal, _t.bytesTotal, _get_html5_duration());\r
- _t._onload(1);\r
- }\r
- }, false);\r
-\r
- _add('canplay', function(e) {\r
- _s._wD('HTML5::canplay: '+_t.sID);\r
- // enough has loaded to play\r
- _t._onbufferchange(0);\r
- },false);\r
-\r
- _add('waiting', function(e) {\r
- _s._wD('HTML5::waiting: '+_t.sID);\r
- // playback faster than download rate, etc.\r
- _t._onbufferchange(1);\r
- },false);\r
-\r
- _add('progress', function(e) { // not supported everywhere yet..\r
- _s._wD('HTML5::progress: '+_t.sID+': loaded/total: '+(e.loaded||0)+','+(e.total||1));\r
- if (!_t.loaded && _a) {\r
- _t._onbufferchange(0); // if progress, likely not buffering\r
- _t._whileloading(e.loaded||0, e.total||1, _get_html5_duration());\r
- }\r
- }, false);\r
-\r
- _add('error', function(e) {\r
- if (_a) {\r
- _s._wD('HTML5::error: '+_a.error.code);\r
- // call load with error state?\r
- _t._onload(0);\r
- }\r
- }, false);\r
-\r
- _add('loadstart', function(e) {\r
- _s._wD('HTML5::loadstart: '+_t.sID);\r
- // assume buffering at first\r
- _t._onbufferchange(1);\r
- }, false);\r
-\r
- _add('play', function(e) {\r
- _s._wD('HTML5::play: '+_t.sID);\r
- // once play starts, no buffering\r
- _t._onbufferchange(0);\r
- }, false);\r
-\r
- // TODO: verify if this is actually implemented anywhere yet.\r
- _add('playing', function(e) {\r
- _s._wD('HTML5::playing: '+_t.sID);\r
- // once play starts, no buffering\r
- _t._onbufferchange(0);\r
- }, false);\r
-\r
- _add('timeupdate', function(e) {\r
- _t._onTimer();\r
- }, false);\r
-\r
- // avoid stupid premature event-firing bug in Safari(?)\r
- setTimeout(function(){\r
- if (_t && _a) {\r
- _add('ended',function(e) {\r
- _s._wD('HTML5::ended: '+_t.sID);\r
- _t._onfinish();\r
- }, false);\r
- }\r
- }, 250);\r
-\r
- };\r
-\r
- // --- "private" methods called by Flash ---\r
-\r
- this._whileloading = function(nBytesLoaded, nBytesTotal, nDuration, nBufferLength) {\r
- _t.bytesLoaded = nBytesLoaded;\r
- _t.bytesTotal = nBytesTotal;\r
- _t.duration = Math.floor(nDuration);\r
- if (!_t._iO.isMovieStar) {\r
- _t.durationEstimate = parseInt((_t.bytesTotal / _t.bytesLoaded) * _t.duration, 10);\r
- if (_t.durationEstimate === undefined) {\r
- // reported bug?\r
- _t.durationEstimate = _t.duration;\r
- }\r
- _t.bufferLength = nBufferLength;\r
- if ((_t._iO.isMovieStar || _t.readyState !== 3) && _t._iO.whileloading) {\r
- _t._iO.whileloading.apply(_t);\r
- }\r
- } else {\r
- _t.durationEstimate = _t.duration;\r
- if (_t.readyState !== 3 && _t._iO.whileloading) {\r
- _t._iO.whileloading.apply(_t);\r
- }\r
- }\r
- };\r
-\r
- this._onid3 = function(oID3PropNames, oID3Data) {\r
- // oID3PropNames: string array (names)\r
- // ID3Data: string array (data)\r
- _s._wD('SMSound._onid3(): "' + this.sID + '" ID3 data received.');\r
- var oData = [], i, j;\r
- for (i = 0, j = oID3PropNames.length; i < j; i++) {\r
- oData[oID3PropNames[i]] = oID3Data[i];\r
- }\r
- _t.id3 = _mergeObjects(_t.id3, oData);\r
- if (_t._iO.onid3) {\r
- _t._iO.onid3.apply(_t);\r
- }\r
- };\r
-\r
- this._whileplaying = function(nPosition, oPeakData, oWaveformDataLeft, oWaveformDataRight, oEQData) {\r
-\r
- if (isNaN(nPosition) || nPosition === null) {\r
- return false; // Flash may return NaN at times\r
- }\r
- if (_t.playState === 0 && nPosition > 0) {\r
- // can happen at the end of a video where nPosition === 33 for some reason, after finishing.???\r
- // can also happen with a normal stop operation. This resets the position to 0.\r
- nPosition = 0;\r
- }\r
- _t.position = nPosition;\r
- _t.processOnPosition();\r
- if (_fV > 8 && !_t.isHTML5) {\r
- if (_t._iO.usePeakData && typeof oPeakData !== 'undefined' && oPeakData) {\r
- _t.peakData = {\r
- left: oPeakData.leftPeak,\r
- right: oPeakData.rightPeak\r
- };\r
- }\r
- if (_t._iO.useWaveformData && typeof oWaveformDataLeft !== 'undefined' && oWaveformDataLeft) {\r
- _t.waveformData = {\r
- left: oWaveformDataLeft.split(','),\r
- right: oWaveformDataRight.split(',')\r
- };\r
- }\r
- if (_t._iO.useEQData) {\r
- if (typeof oEQData !== 'undefined' && oEQData && oEQData.leftEQ) {\r
- var eqLeft = oEQData.leftEQ.split(',');\r
- _t.eqData = eqLeft;\r
- _t.eqData.left = eqLeft;\r
- if (typeof oEQData.rightEQ !== 'undefined' && oEQData.rightEQ) {\r
- _t.eqData.right = oEQData.rightEQ.split(',');\r
- }\r
- }\r
- }\r
- }\r
- if (_t.playState === 1) {\r
- // special case/hack: ensure buffering is false (instant load from cache, thus buffering stuck at 1?)\r
- if (!_t.isHTML5 && _t.isBuffering) {\r
- _t._onbufferchange(0);\r
- }\r
- if (_t._iO.whileplaying) {\r
- _t._iO.whileplaying.apply(_t); // flash may call after actual finish\r
- }\r
-\r
- if ((_t.loaded || (!_t.loaded && _t._iO.isMovieStar)) && _t._iO.onbeforefinish && _t._iO.onbeforefinishtime && !_t.didBeforeFinish && _t.duration - _t.position <= _t._iO.onbeforefinishtime) {\r
- _s._wD('duration-position <= onbeforefinishtime: ' + _t.duration + ' - ' + _t.position + ' <= ' + _t._iO.onbeforefinishtime + ' (' + (_t.duration - _t.position) + ')');\r
- _t._onbeforefinish();\r
- }\r
- }\r
- };\r
-\r
- this._onconnect = function(bSuccess) {\r
- var fN = 'SMSound._onconnect(): ';\r
- bSuccess = (bSuccess === 1);\r
- _s._wD(fN+'"'+_t.sID+'"'+(bSuccess?' connected.':' failed to connect? - '+_t.url), (bSuccess?1:2));\r
- _t.connected = bSuccess;\r
- if (bSuccess) {\r
- _t.failures = 0;\r
- if (_t._iO.autoLoad || _t._iO.autoPlay) {\r
- _t.load(_t._iO);\r
- }\r
- if (_t._iO.autoPlay) {\r
- _t.play();\r
- }\r
- if (_t._iO.onconnect) {\r
- _t._iO.onconnect.apply(_t,[bSuccess]);\r
- }\r
- }\r
- };\r
-\r
- this._onload = function(nSuccess) {\r
- var fN = 'SMSound._onload(): ';\r
- nSuccess = (nSuccess === 1?true:false);\r
- _s._wD(fN + '"' + _t.sID + '"' + (nSuccess?' loaded.':' failed to load? - ' + _t.url), (nSuccess?1:2));\r
- // <d>\r
- if (!nSuccess && !_t.isHTML5) {\r
- if (_s.sandbox.noRemote === true) {\r
- _s._wD(fN + _str('noNet'), 1);\r
- }\r
- if (_s.sandbox.noLocal === true) {\r
- _s._wD(fN + _str('noLocal'), 1);\r
- }\r
- }\r
- // </d>\r
- _t.loaded = nSuccess;\r
- _t.readyState = nSuccess?3:2;\r
- if (_t._iO.onload) {\r
- _t._iO.onload.apply(_t);\r
- }\r
- };\r
-\r
- // Only fire the onfailure callback once because after one failure we often get another.\r
- // At this point we just recreate failed sounds rather than trying to reconnect.\r
- this._onfailure = function(msg) {\r
- _t.failures++;\r
- _s._wD('SMSound._onfailure(): "'+_t.sID+'" count '+_t.failures);\r
- if (_t._iO.onfailure && _t.failures === 1) {\r
- _t._iO.onfailure(_t, msg);\r
- } else {\r
- _s._wD('SMSound._onfailure(): ignoring');\r
- }\r
- };\r
-\r
- this._onbeforefinish = function() {\r
- if (!_t.didBeforeFinish) {\r
- _t.didBeforeFinish = true;\r
- if (_t._iO.onbeforefinish) {\r
- _s._wD('SMSound._onbeforefinish(): "' + _t.sID + '"');\r
- _t._iO.onbeforefinish.apply(_t);\r
- }\r
- }\r
- };\r
-\r
- this._onjustbeforefinish = function(msOffset) {\r
- // msOffset: "end of sound" delay actual value (eg. 200 msec, value at event fire time was 187)\r
- if (!_t.didJustBeforeFinish) {\r
- _t.didJustBeforeFinish = true;\r
- if (_t._iO.onjustbeforefinish) {\r
- _s._wD('SMSound._onjustbeforefinish(): "' + _t.sID + '"');\r
- _t._iO.onjustbeforefinish.apply(_t);\r
- }\r
- }\r
- };\r
-\r
- this._onfinish = function() {\r
- // sound has finished playing\r
- // TODO: calling user-defined onfinish() should happen after setPosition(0)\r
- // OR: onfinish() and then setPosition(0) is bad.\r
- _t._onbufferchange(0); // ensure buffer has ended\r
- _t.resetOnPosition(0);\r
- if (_t._iO.onbeforefinishcomplete) {\r
- _t._iO.onbeforefinishcomplete.apply(_t);\r
- }\r
- // reset some state items\r
- _t.didBeforeFinish = false;\r
- _t.didJustBeforeFinish = false;\r
- if (_t.instanceCount) {\r
- _t.instanceCount--;\r
- if (!_t.instanceCount) {\r
- // reset instance options\r
- // _t.setPosition(0);\r
- _t.playState = 0;\r
- _t.paused = false;\r
- _t.instanceCount = 0;\r
- _t.instanceOptions = {};\r
- _stop_html5_timer();\r
- }\r
- // KJV May interfere with multi-shot events, but either way, instanceCount is sometimes 0 when it should not be.\r
- if (!_t.instanceCount || _t._iO.multiShotEvents) {\r
- // fire onfinish for last, or every instance\r
- if (_t._iO.onfinish) {\r
- _s._wD('SMSound._onfinish(): "' + _t.sID + '"');\r
- _t._iO.onfinish.apply(_t);\r
- } else if (_t.isHTML5) {\r
- // assume safe to unload, etc.\r
- _t.unload();\r
- }\r
- }\r
- }\r
- };\r
-\r
- this._onmetadata = function(oMetaData) {\r
- // movieStar mode only\r
- var fN = 'SMSound.onmetadata()';\r
- _s._wD(fN);\r
- // Contains a subset of metadata. Note that files may have their own unique metadata.\r
- // http://livedocs.adobe.com/flash/9.0/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00000267.html\r
- if (!oMetaData.width && !oMetaData.height) {\r
- _wDS('noWH');\r
- oMetaData.width = 320;\r
- oMetaData.height = 240;\r
- }\r
- _t.metadata = oMetaData; // potentially-large object from flash\r
- _t.width = oMetaData.width;\r
- _t.height = oMetaData.height;\r
- if (_t._iO.onmetadata) {\r
- _s._wD(fN + ': "' + _t.sID + '"');\r
- _t._iO.onmetadata.apply(_t);\r
- }\r
- _s._wD(fN + ' complete');\r
- };\r
-\r
- this._onbufferchange = function(nIsBuffering) {\r
- var fN = 'SMSound._onbufferchange()';\r
- if (_t.playState === 0) {\r
- // ignore if not playing\r
- return false;\r
- }\r
- if ((nIsBuffering && _t.isBuffering) || (!nIsBuffering && !_t.isBuffering)) {\r
- // _s._wD(fN + ': Note: buffering already = '+nIsBuffering);\r
- return false;\r
- }\r
- _t.isBuffering = (nIsBuffering === 1?true:false);\r
- if (_t._iO.onbufferchange) {\r
- _s._wD(fN + ': ' + nIsBuffering);\r
- _t._iO.onbufferchange.apply(_t);\r
- }\r
- };\r
-\r
- this._ondataerror = function(sError) {\r
- // flash 9 wave/eq data handler\r
- if (_t.playState > 0) { // hack: called at start, and end from flash at/after onfinish().\r
- _s._wD('SMSound._ondataerror(): ' + sError);\r
- if (_t._iO.ondataerror) {\r
- _t._iO.ondataerror.apply(_t);\r
- }\r
- }\r
- };\r
-\r
- }; // SMSound()\r
-\r
-\r
- // register a few event handlers\r
- \r
- if (!_s.hasHTML5 || _needsFlash) {\r
- // only applies to Flash mode.\r
- if (window.addEventListener) {\r
- window.addEventListener('focus', _handleFocus, false);\r
- window.addEventListener('load', _s.beginDelayedInit, false);\r
- window.addEventListener('unload', _s.destruct, false);\r
- if (_tryInitOnFocus) {\r
- window.addEventListener('mousemove', _handleFocus, false); // massive Safari focus hack\r
- }\r
- } else if (window.attachEvent) {\r
- window.attachEvent('onfocus', _handleFocus);\r
- window.attachEvent('onload', _s.beginDelayedInit);\r
- window.attachEvent('unload', _s.destruct);\r
- } else {\r
- // no add/attachevent support - safe to assume no JS -> Flash either.\r
- _debugTS('onload', false);\r
- soundManager.onerror();\r
- soundManager.disable();\r
- }\r
- }\r
-\r
- _dcIE = function() {\r
- if (document.readyState === 'complete') {\r
- _dcLoaded();\r
- document.detachEvent('onreadystatechange', _dcIE);\r
- }\r
- };\r
-\r
- if (document.addEventListener) {\r
- document.addEventListener('DOMContentLoaded', _dcLoaded, false);\r
- } else if (document.attachEvent) {\r
- document.attachEvent('onreadystatechange', _dcIE);\r
- }\r
-\r
- if (document.readyState === 'complete') {\r
- setTimeout(_dcLoaded,100);\r
- }\r
-\r
-} // SoundManager()\r
-\r
-// var SM2_DEFER = true;\r
-// un-comment here or define in your own script to prevent immediate SoundManager() constructor call+start-up.\r
-\r
-// if deferring, construct later with window.soundManager = new SoundManager(); followed by soundManager.beginDelayedInit();\r
-\r
-if (typeof SM2_DEFER === 'undefined' || !SM2_DEFER) {\r
- soundManager = new SoundManager();\r
-}\r
-\r
-// expose public interfaces\r
-window.SoundManager = SoundManager; // SoundManager constructor\r
-window.soundManager = soundManager; // public instance: API, Flash callbacks etc.\r
-\r
-}(window)); // invocation closure\r