1 | /** @license
|
---|
2 | * SoundManager 2: JavaScript Sound for the Web
|
---|
3 | * ----------------------------------------------
|
---|
4 | * http://schillmania.com/projects/soundmanager2/
|
---|
5 | *
|
---|
6 | * Copyright (c) 2007, Scott Schiller. All rights reserved.
|
---|
7 | * Code provided under the BSD License:
|
---|
8 | * http://schillmania.com/projects/soundmanager2/license.txt
|
---|
9 | *
|
---|
10 | * V2.97a.20110801
|
---|
11 | */
|
---|
12 |
|
---|
13 | /*global window, SM2_DEFER, sm2Debugger, console, document, navigator, setTimeout, setInterval, clearInterval, Audio */
|
---|
14 | /*jslint regexp: true, sloppy: true, white: true, nomen: true, plusplus: true */
|
---|
15 |
|
---|
16 | (function(window) {
|
---|
17 |
|
---|
18 | var soundManager = null;
|
---|
19 |
|
---|
20 | function SoundManager(smURL, smID) {
|
---|
21 |
|
---|
22 | this.flashVersion = 8; // version of flash to require, either 8 or 9. Some API features require Flash 9.
|
---|
23 | this.debugMode = true; // enable debugging output (div#soundmanager-debug, OR console if available+configured)
|
---|
24 | this.debugFlash = false; // enable debugging output inside SWF, troubleshoot Flash/browser issues
|
---|
25 | this.useConsole = true; // use firebug/safari console.log()-type debug console if available
|
---|
26 | this.consoleOnly = false; // if console is being used, do not create/write to #soundmanager-debug
|
---|
27 | this.waitForWindowLoad = false; // force SM2 to wait for window.onload() before trying to call soundManager.onload()
|
---|
28 | this.nullURL = 'about:blank'; // path to "null" (empty) MP3 file, used to unload sounds (Flash 8 only)
|
---|
29 | this.allowPolling = true; // allow flash to poll for status update (required for whileplaying() events, peak, sound spectrum functions to work.)
|
---|
30 | this.useFastPolling = false; // uses lower flash timer interval for higher callback frequency, best combined with useHighPerformance
|
---|
31 | this.useMovieStar = true; // enable support for Flash 9.0r115+ (codename "MovieStar") MPEG4 audio formats (AAC, M4V, FLV, MOV etc.)
|
---|
32 | this.bgColor = '#ffffff'; // movie (.swf) background color, eg. '#000000'
|
---|
33 | this.useHighPerformance = false; // position:fixed flash movie can help increase js/flash speed, minimize lag
|
---|
34 | this.flashPollingInterval = null; // msec for polling interval. Defaults to 50 unless useFastPolling = true.
|
---|
35 | this.flashLoadTimeout = 1000; // msec to wait for flash movie to load before failing (0 = infinity)
|
---|
36 | this.wmode = null; // string: flash rendering mode - null, transparent, opaque (last two allow layering of HTML on top)
|
---|
37 | this.allowScriptAccess = 'always'; // for scripting the SWF (object/embed property), either 'always' or 'sameDomain'
|
---|
38 | this.useFlashBlock = false; // *requires flashblock.css, see demos* - allow recovery from flash blockers. Wait indefinitely and apply timeout CSS to SWF, if applicable.
|
---|
39 | this.useHTML5Audio = true; // Beta feature: Use HTML5 Audio() where API is supported (most Safari, Chrome versions), Firefox (no MP3/MP4.) Ideally, transparent vs. Flash API where possible.
|
---|
40 | this.html5Test = /^(probably|maybe)$/i; // HTML5 Audio() format support test. Use /^probably$/i; if you want to be more conservative.
|
---|
41 | this.preferFlash = true; // (experimental) if true and flash support present, will try to use flash for MP3/MP4 as needed since HTML5 audio support is still quirky in browsers.
|
---|
42 |
|
---|
43 | this.audioFormats = {
|
---|
44 | /*
|
---|
45 | * determines HTML5 support + flash requirements.
|
---|
46 | * if no support for a "required" format, SM2 will fail to start.
|
---|
47 | * flash fallback is used for MP3 or MP4 if HTML5 can't play it (or if preferFlash = true)
|
---|
48 | * multiple MIME types may be tested while trying to get a positive canPlayType() response.
|
---|
49 | */
|
---|
50 | 'mp3': {
|
---|
51 | 'type': ['audio/mpeg; codecs="mp3"', 'audio/mpeg', 'audio/mp3', 'audio/MPA', 'audio/mpa-robust'],
|
---|
52 | 'required': true
|
---|
53 | },
|
---|
54 | 'mp4': {
|
---|
55 | 'related': ['aac','m4a'], // additional formats under the MP4 container
|
---|
56 | 'type': ['audio/mp4; codecs="mp4a.40.2"', 'audio/aac', 'audio/x-m4a', 'audio/MP4A-LATM', 'audio/mpeg4-generic'],
|
---|
57 | 'required': false
|
---|
58 | },
|
---|
59 | 'ogg': {
|
---|
60 | 'type': ['audio/ogg; codecs=vorbis'],
|
---|
61 | 'required': false
|
---|
62 | },
|
---|
63 | 'wav': {
|
---|
64 | 'type': ['audio/wav; codecs="1"', 'audio/wav', 'audio/wave', 'audio/x-wav'],
|
---|
65 | 'required': false
|
---|
66 | }
|
---|
67 | };
|
---|
68 |
|
---|
69 | this.defaultOptions = {
|
---|
70 | '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)
|
---|
71 | 'stream': true, // allows playing before entire file has loaded (recommended)
|
---|
72 | 'autoPlay': false, // enable playing of file as soon as possible (much faster if "stream" is true)
|
---|
73 | 'loops': 1, // how many times to repeat the sound (position will wrap around to 0, setPosition() will break out of loop when >0)
|
---|
74 | 'onid3': null, // callback function for "ID3 data is added/available"
|
---|
75 | 'onload': null, // callback function for "load finished"
|
---|
76 | 'whileloading': null, // callback function for "download progress update" (X of Y bytes received)
|
---|
77 | 'onplay': null, // callback for "play" start
|
---|
78 | 'onpause': null, // callback for "pause"
|
---|
79 | 'onresume': null, // callback for "resume" (pause toggle)
|
---|
80 | 'whileplaying': null, // callback during play (position update)
|
---|
81 | 'onstop': null, // callback for "user stop"
|
---|
82 | 'onfailure': null, // callback function for when playing fails
|
---|
83 | 'onfinish': null, // callback function for "sound finished playing"
|
---|
84 | 'onbeforefinish': null, // callback for "before sound finished playing (at [time])"
|
---|
85 | 'onbeforefinishtime': 5000, // offset (milliseconds) before end of sound to trigger beforefinish (eg. 1000 msec = 1 second)
|
---|
86 | 'onbeforefinishcomplete': null,// function to call when said sound finishes playing
|
---|
87 | 'onjustbeforefinish': null, // callback for [n] msec before end of current sound
|
---|
88 | 'onjustbeforefinishtime': 200, // [n] - if not using, set to 0 (or null handler) and event will not fire.
|
---|
89 | 'multiShot': true, // let sounds "restart" or layer on top of each other when played multiple times, rather than one-shot/one at a time
|
---|
90 | 'multiShotEvents': false, // fire multiple sound events (currently onfinish() only) when multiShot is enabled
|
---|
91 | 'position': null, // offset (milliseconds) to seek to within loaded sound data.
|
---|
92 | 'pan': 0, // "pan" settings, left-to-right, -100 to 100
|
---|
93 | 'type': null, // MIME-like hint for file pattern / canPlay() tests, eg. audio/mp3
|
---|
94 | 'usePolicyFile': false, // enable crossdomain.xml request for audio on remote domains (for ID3/waveform access)
|
---|
95 | 'volume': 100 // self-explanatory. 0-100, the latter being the max.
|
---|
96 | };
|
---|
97 |
|
---|
98 | this.flash9Options = { // flash 9-only options, merged into defaultOptions if flash 9 is being used
|
---|
99 | 'isMovieStar': null, // "MovieStar" MPEG4 audio mode. Null (default) = auto detect MP4, AAC etc. based on URL. true = force on, ignore URL
|
---|
100 | 'usePeakData': false, // enable left/right channel peak (level) data
|
---|
101 | 'useWaveformData': false, // enable sound spectrum (raw waveform data) - WARNING: CPU-INTENSIVE: may set CPUs on fire.
|
---|
102 | 'useEQData': false, // enable sound EQ (frequency spectrum data) - WARNING: Also CPU-intensive.
|
---|
103 | 'onbufferchange': null, // callback for "isBuffering" property change
|
---|
104 | 'ondataerror': null // callback for waveform/eq data access error (flash playing audio in other tabs/domains)
|
---|
105 | };
|
---|
106 |
|
---|
107 | this.movieStarOptions = { // flash 9.0r115+ MPEG4 audio options, merged into defaultOptions if flash 9+movieStar mode is enabled
|
---|
108 | 'bufferTime': 3, // seconds of data to buffer before playback begins (null = flash default of 0.1 seconds - if AAC playback is gappy, try increasing.)
|
---|
109 | 'serverURL': null, // rtmp: FMS or FMIS server to connect to, required when requesting media via RTMP or one of its variants
|
---|
110 | 'onconnect': null, // rtmp: callback for connection to flash media server
|
---|
111 | 'duration': null // rtmp: song duration (msec)
|
---|
112 | };
|
---|
113 |
|
---|
114 | this.version = null;
|
---|
115 | this.versionNumber = 'V2.97a.20110801';
|
---|
116 | this.movieURL = null;
|
---|
117 | this.url = (smURL || null);
|
---|
118 | this.altURL = null;
|
---|
119 | this.swfLoaded = false;
|
---|
120 | this.enabled = false;
|
---|
121 | this.o = null;
|
---|
122 | this.movieID = 'sm2-container';
|
---|
123 | this.id = (smID || 'sm2movie');
|
---|
124 | this.swfCSS = {
|
---|
125 | 'swfBox': 'sm2-object-box',
|
---|
126 | 'swfDefault': 'movieContainer',
|
---|
127 | 'swfError': 'swf_error', // SWF loaded, but SM2 couldn't start (other error)
|
---|
128 | 'swfTimedout': 'swf_timedout',
|
---|
129 | 'swfLoaded': 'swf_loaded',
|
---|
130 | 'swfUnblocked': 'swf_unblocked', // or loaded OK
|
---|
131 | 'sm2Debug': 'sm2_debug',
|
---|
132 | 'highPerf': 'high_performance',
|
---|
133 | 'flashDebug': 'flash_debug'
|
---|
134 | };
|
---|
135 | this.oMC = null;
|
---|
136 | this.sounds = {};
|
---|
137 | this.soundIDs = [];
|
---|
138 | this.muted = false;
|
---|
139 | this.debugID = 'soundmanager-debug';
|
---|
140 | this.debugURLParam = /([#?&])debug=1/i;
|
---|
141 | this.specialWmodeCase = false;
|
---|
142 | this.didFlashBlock = false;
|
---|
143 |
|
---|
144 | this.filePattern = null;
|
---|
145 | this.filePatterns = {
|
---|
146 | 'flash8': /\.mp3(\?.*)?$/i,
|
---|
147 | 'flash9': /\.mp3(\?.*)?$/i
|
---|
148 | };
|
---|
149 |
|
---|
150 | this.baseMimeTypes = /^\s*audio\/(?:x-)?(?:mp(?:eg|3))\s*(?:$|;)/i; // mp3
|
---|
151 | this.netStreamMimeTypes = /^\s*audio\/(?:x-)?(?:mp(?:eg|3))\s*(?:$|;)/i; // mp3, mp4, aac etc.
|
---|
152 | this.netStreamTypes = ['aac', 'flv', 'mov', 'mp4', 'm4v', 'f4v', 'm4a', 'mp4v', '3gp', '3g2']; // Flash v9.0r115+ "moviestar" formats
|
---|
153 | this.netStreamPattern = new RegExp('\\.(' + this.netStreamTypes.join('|') + ')(\\?.*)?$', 'i');
|
---|
154 | this.mimePattern = this.baseMimeTypes;
|
---|
155 |
|
---|
156 | this.features = {
|
---|
157 | 'buffering': false,
|
---|
158 | 'peakData': false,
|
---|
159 | 'waveformData': false,
|
---|
160 | 'eqData': false,
|
---|
161 | 'movieStar': false
|
---|
162 | };
|
---|
163 |
|
---|
164 | this.sandbox = {
|
---|
165 | // <d>
|
---|
166 | 'type': null,
|
---|
167 | 'types': {
|
---|
168 | 'remote': 'remote (domain-based) rules',
|
---|
169 | 'localWithFile': 'local with file access (no internet access)',
|
---|
170 | 'localWithNetwork': 'local with network (internet access only, no local access)',
|
---|
171 | 'localTrusted': 'local, trusted (local+internet access)'
|
---|
172 | },
|
---|
173 | 'description': null,
|
---|
174 | 'noRemote': null,
|
---|
175 | 'noLocal': null
|
---|
176 | // </d>
|
---|
177 | };
|
---|
178 |
|
---|
179 | this.hasHTML5 = (typeof Audio !== 'undefined' && typeof new Audio().canPlayType !== 'undefined'); // switch for handling logic
|
---|
180 |
|
---|
181 | // stores canPlayType() results, etc. treat as read-only.
|
---|
182 | this.html5 = {
|
---|
183 | // mp3: boolean
|
---|
184 | // mp4: boolean
|
---|
185 | 'usingFlash': null // set if/when flash fallback is needed
|
---|
186 | };
|
---|
187 |
|
---|
188 | // format support
|
---|
189 | this.flash = {
|
---|
190 | // mp3: boolean
|
---|
191 | // mp4: boolean
|
---|
192 | };
|
---|
193 |
|
---|
194 | this.html5Only = false; // determined at init time
|
---|
195 | this.ignoreFlash = false; // used for special cases (eg. iPad/iPhone/palm OS?)
|
---|
196 |
|
---|
197 | /*
|
---|
198 | * a few private internals
|
---|
199 | */
|
---|
200 |
|
---|
201 | var SMSound,
|
---|
202 | _s = this, _sm = 'soundManager', _smc = _sm+'::', _h5 = 'HTML5::', _id, _ua = navigator.userAgent, _win = window, _wl = _win.location.href.toString(), _fV = this.flashVersion, _doc = document, _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, _delayWaitForEI, _waitForEI, _setVersionInfo, _handleFocus, _strings, _initMovie, _dcLoaded, _didDCLoaded, _getDocument, _createMovie, _catchError, _setPolling, _initDebug, _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, _html5CanPlay, _html5Ext, _dcIE, _testHTML5, _event, _slice = Array.prototype.slice, _useGlobalHTML5Audio = false, _hasFlash, _detectFlash, _badSafariFix, _html5_events, _showSupport,
|
---|
203 | _is_iDevice = _ua.match(/(ipad|iphone|ipod)/i), _likesHTML5 = (_ua.match(/(mobile|pre\/|xoom)/i) || _is_iDevice), _isIE = _ua.match(/msie/i), _isWebkit = _ua.match(/webkit/i), _isSafari = (_ua.match(/safari/i) && !_ua.match(/chrome/i)), _isOpera = (_ua.match(/opera/i)),
|
---|
204 | _isBadSafari = (!_wl.match(/usehtml5audio/i) && !_wl.match(/sm2\-ignorebadua/i) && _isSafari && _ua.match(/OS X 10_6_([3-7])/i)), // Safari 4 and 5 occasionally fail to load/play HTML5 audio on Snow Leopard 10.6.3 through 10.6.7 due to bug(s) in QuickTime X and/or other underlying frameworks. :/ Confirmed bug. https://bugs.webkit.org/show_bug.cgi?id=32159
|
---|
205 | _hasConsole = (typeof console !== 'undefined' && typeof console.log !== 'undefined'), _isFocused = (typeof _doc.hasFocus !== 'undefined'?_doc.hasFocus():null), _tryInitOnFocus = (_isSafari && typeof _doc.hasFocus === 'undefined'), _okToDisable = !_tryInitOnFocus, _flashMIME = /(mp3|mp4|mpa)/i,
|
---|
206 | _overHTTP = (_doc.location?_doc.location.protocol.match(/http/i):null),
|
---|
207 | _http = (!_overHTTP ? 'http:' : '');
|
---|
208 |
|
---|
209 | this.useAltURL = !_overHTTP; // use altURL if not "online"
|
---|
210 | this._global_a = null;
|
---|
211 |
|
---|
212 | if (_likesHTML5) {
|
---|
213 | // prefer HTML5 for mobile + tablet-like devices, probably more reliable vs. flash at this point.
|
---|
214 | _s.useHTML5Audio = true;
|
---|
215 | _s.preferFlash = false;
|
---|
216 | if (_is_iDevice) {
|
---|
217 | // by default, use global feature. iOS onfinish() -> next may fail otherwise.
|
---|
218 | _s.ignoreFlash = true;
|
---|
219 | _useGlobalHTML5Audio = true;
|
---|
220 | }
|
---|
221 | }
|
---|
222 |
|
---|
223 | /*
|
---|
224 | * public soundManager API
|
---|
225 | */
|
---|
226 |
|
---|
227 | this.ok = function() {
|
---|
228 | return (_needsFlash?(_didInit && !_disabled):(_s.useHTML5Audio && _s.hasHTML5));
|
---|
229 | };
|
---|
230 |
|
---|
231 | this.supported = this.ok; // legacy
|
---|
232 |
|
---|
233 | this.getMovie = function(smID) {
|
---|
234 | return _isIE?_win[smID]:(_isSafari?_id(smID) || _doc[smID]:_id(smID));
|
---|
235 | };
|
---|
236 |
|
---|
237 | this.createSound = function(oOptions) {
|
---|
238 | var _cs = _sm+'.createSound(): ',
|
---|
239 | thisOptions = null, oSound = null, _tO = null;
|
---|
240 | if (!_didInit || !_s.ok()) {
|
---|
241 | _complain(_cs + _str(!_didInit?'notReady':'notOK'));
|
---|
242 | return false;
|
---|
243 | }
|
---|
244 | if (arguments.length === 2) {
|
---|
245 | // function overloading in JS! :) ..assume simple createSound(id,url) use case
|
---|
246 | oOptions = {
|
---|
247 | 'id': arguments[0],
|
---|
248 | 'url': arguments[1]
|
---|
249 | };
|
---|
250 | }
|
---|
251 | thisOptions = _mixin(oOptions); // inherit from defaultOptions
|
---|
252 | _tO = thisOptions; // alias
|
---|
253 | // <d>
|
---|
254 | if (_tO.id.toString().charAt(0).match(/^[0-9]$/)) {
|
---|
255 | _s._wD(_cs + _str('badID', _tO.id), 2);
|
---|
256 | }
|
---|
257 | _s._wD(_cs + _tO.id + ' (' + _tO.url + ')', 1);
|
---|
258 | // </d>
|
---|
259 | if (_idCheck(_tO.id, true)) {
|
---|
260 | _s._wD(_cs + _tO.id + ' exists', 1);
|
---|
261 | return _s.sounds[_tO.id];
|
---|
262 | }
|
---|
263 |
|
---|
264 | function make() {
|
---|
265 | thisOptions = _loopFix(thisOptions);
|
---|
266 | _s.sounds[_tO.id] = new SMSound(_tO);
|
---|
267 | _s.soundIDs.push(_tO.id);
|
---|
268 | return _s.sounds[_tO.id];
|
---|
269 | }
|
---|
270 |
|
---|
271 | if (_html5OK(_tO)) {
|
---|
272 | oSound = make();
|
---|
273 | _s._wD('Loading sound '+_tO.id+' via HTML5');
|
---|
274 | oSound._setup_html5(_tO);
|
---|
275 | } else {
|
---|
276 | if (_fV > 8 && _s.useMovieStar) {
|
---|
277 | if (_tO.isMovieStar === null) {
|
---|
278 | _tO.isMovieStar = ((_tO.serverURL || (_tO.type?_tO.type.match(_s.netStreamPattern):false)||_tO.url.match(_s.netStreamPattern))?true:false);
|
---|
279 | }
|
---|
280 | if (_tO.isMovieStar) {
|
---|
281 | _s._wD(_cs + 'using MovieStar handling');
|
---|
282 | }
|
---|
283 | if (_tO.isMovieStar) {
|
---|
284 | if (_tO.usePeakData) {
|
---|
285 | _wDS('noPeak');
|
---|
286 | _tO.usePeakData = false;
|
---|
287 | }
|
---|
288 | if (_tO.loops > 1) {
|
---|
289 | _wDS('noNSLoop');
|
---|
290 | }
|
---|
291 | }
|
---|
292 | }
|
---|
293 | _tO = _policyFix(_tO, _cs);
|
---|
294 | oSound = make();
|
---|
295 | if (_fV === 8) {
|
---|
296 | _s.o._createSound(_tO.id, _tO.onjustbeforefinishtime, _tO.loops||1, _tO.usePolicyFile);
|
---|
297 | } else {
|
---|
298 | _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.autoLoad, _tO.usePolicyFile);
|
---|
299 | if (!_tO.serverURL) {
|
---|
300 | // We are connected immediately
|
---|
301 | oSound.connected = true;
|
---|
302 | if (_tO.onconnect) {
|
---|
303 | _tO.onconnect.apply(oSound);
|
---|
304 | }
|
---|
305 | }
|
---|
306 | }
|
---|
307 |
|
---|
308 | if (!_tO.serverURL && (_tO.autoLoad || _tO.autoPlay)) {
|
---|
309 | oSound.load(_tO); // call load for non-rtmp streams
|
---|
310 | }
|
---|
311 | }
|
---|
312 | if (!_tO.serverURL && _tO.autoPlay) { // rtmp will play in onconnect
|
---|
313 | oSound.play();
|
---|
314 | }
|
---|
315 | return oSound;
|
---|
316 | };
|
---|
317 |
|
---|
318 | this.destroySound = function(sID, _bFromSound) {
|
---|
319 | // explicitly destroy a sound before normal page unload, etc.
|
---|
320 | if (!_idCheck(sID)) {
|
---|
321 | return false;
|
---|
322 | }
|
---|
323 | var oS = _s.sounds[sID], i;
|
---|
324 | oS._iO = {}; // Disable all callbacks while the sound is being destroyed
|
---|
325 | oS.stop();
|
---|
326 | oS.unload();
|
---|
327 | for (i = 0; i < _s.soundIDs.length; i++) {
|
---|
328 | if (_s.soundIDs[i] === sID) {
|
---|
329 | _s.soundIDs.splice(i, 1);
|
---|
330 | break;
|
---|
331 | }
|
---|
332 | }
|
---|
333 | if (!_bFromSound) {
|
---|
334 | // ignore if being called from SMSound instance
|
---|
335 | oS.destruct(true);
|
---|
336 | }
|
---|
337 | oS = null;
|
---|
338 | delete _s.sounds[sID];
|
---|
339 | return true;
|
---|
340 | };
|
---|
341 |
|
---|
342 | this.load = function(sID, oOptions) {
|
---|
343 | if (!_idCheck(sID)) {
|
---|
344 | return false;
|
---|
345 | }
|
---|
346 | return _s.sounds[sID].load(oOptions);
|
---|
347 | };
|
---|
348 |
|
---|
349 | this.unload = function(sID) {
|
---|
350 | if (!_idCheck(sID)) {
|
---|
351 | return false;
|
---|
352 | }
|
---|
353 | return _s.sounds[sID].unload();
|
---|
354 | };
|
---|
355 |
|
---|
356 | this.play = function(sID, oOptions) {
|
---|
357 | var fN = _sm+'.play(): ';
|
---|
358 | if (!_didInit || !_s.ok()) {
|
---|
359 | _complain(fN + _str(!_didInit?'notReady':'notOK'));
|
---|
360 | return false;
|
---|
361 | }
|
---|
362 | if (!_idCheck(sID)) {
|
---|
363 | if (!(oOptions instanceof Object)) {
|
---|
364 | oOptions = {
|
---|
365 | url: oOptions
|
---|
366 | }; // overloading use case: play('mySound','/path/to/some.mp3');
|
---|
367 | }
|
---|
368 | if (oOptions && oOptions.url) {
|
---|
369 | // overloading use case, create+play: .play('someID',{url:'/path/to.mp3'});
|
---|
370 | _s._wD(fN + 'attempting to create "' + sID + '"', 1);
|
---|
371 | oOptions.id = sID;
|
---|
372 | return _s.createSound(oOptions).play();
|
---|
373 | } else {
|
---|
374 | return false;
|
---|
375 | }
|
---|
376 | }
|
---|
377 | return _s.sounds[sID].play(oOptions);
|
---|
378 | };
|
---|
379 |
|
---|
380 | this.start = this.play; // just for convenience
|
---|
381 |
|
---|
382 | this.setPosition = function(sID, nMsecOffset) {
|
---|
383 | if (!_idCheck(sID)) {
|
---|
384 | return false;
|
---|
385 | }
|
---|
386 | return _s.sounds[sID].setPosition(nMsecOffset);
|
---|
387 | };
|
---|
388 |
|
---|
389 | this.stop = function(sID) {
|
---|
390 | if (!_idCheck(sID)) {
|
---|
391 | return false;
|
---|
392 | }
|
---|
393 | _s._wD(_sm+'.stop(' + sID + ')', 1);
|
---|
394 | return _s.sounds[sID].stop();
|
---|
395 | };
|
---|
396 |
|
---|
397 | this.stopAll = function() {
|
---|
398 | var oSound;
|
---|
399 | _s._wD(_sm+'.stopAll()', 1);
|
---|
400 | for (oSound in _s.sounds) {
|
---|
401 | if (_s.sounds.hasOwnProperty(oSound)) {
|
---|
402 | _s.sounds[oSound].stop(); // apply only to sound objects
|
---|
403 | }
|
---|
404 | }
|
---|
405 | };
|
---|
406 |
|
---|
407 | this.pause = function(sID) {
|
---|
408 | if (!_idCheck(sID)) {
|
---|
409 | return false;
|
---|
410 | }
|
---|
411 | return _s.sounds[sID].pause();
|
---|
412 | };
|
---|
413 |
|
---|
414 | this.pauseAll = function() {
|
---|
415 | var i;
|
---|
416 | for (i = _s.soundIDs.length; i--;) {
|
---|
417 | _s.sounds[_s.soundIDs[i]].pause();
|
---|
418 | }
|
---|
419 | };
|
---|
420 |
|
---|
421 | this.resume = function(sID) {
|
---|
422 | if (!_idCheck(sID)) {
|
---|
423 | return false;
|
---|
424 | }
|
---|
425 | return _s.sounds[sID].resume();
|
---|
426 | };
|
---|
427 |
|
---|
428 | this.resumeAll = function() {
|
---|
429 | var i;
|
---|
430 | for (i = _s.soundIDs.length; i--;) {
|
---|
431 | _s.sounds[_s.soundIDs[i]].resume();
|
---|
432 | }
|
---|
433 | };
|
---|
434 |
|
---|
435 | this.togglePause = function(sID) {
|
---|
436 | if (!_idCheck(sID)) {
|
---|
437 | return false;
|
---|
438 | }
|
---|
439 | return _s.sounds[sID].togglePause();
|
---|
440 | };
|
---|
441 |
|
---|
442 | this.setPan = function(sID, nPan) {
|
---|
443 | if (!_idCheck(sID)) {
|
---|
444 | return false;
|
---|
445 | }
|
---|
446 | return _s.sounds[sID].setPan(nPan);
|
---|
447 | };
|
---|
448 |
|
---|
449 | this.setVolume = function(sID, nVol) {
|
---|
450 | if (!_idCheck(sID)) {
|
---|
451 | return false;
|
---|
452 | }
|
---|
453 | return _s.sounds[sID].setVolume(nVol);
|
---|
454 | };
|
---|
455 |
|
---|
456 | this.mute = function(sID) {
|
---|
457 | var fN = _sm+'.mute(): ',
|
---|
458 | i = 0;
|
---|
459 | if (typeof sID !== 'string') {
|
---|
460 | sID = null;
|
---|
461 | }
|
---|
462 | if (!sID) {
|
---|
463 | _s._wD(fN + 'Muting all sounds');
|
---|
464 | for (i = _s.soundIDs.length; i--;) {
|
---|
465 | _s.sounds[_s.soundIDs[i]].mute();
|
---|
466 | }
|
---|
467 | _s.muted = true;
|
---|
468 | } else {
|
---|
469 | if (!_idCheck(sID)) {
|
---|
470 | return false;
|
---|
471 | }
|
---|
472 | _s._wD(fN + 'Muting "' + sID + '"');
|
---|
473 | return _s.sounds[sID].mute();
|
---|
474 | }
|
---|
475 | return true;
|
---|
476 | };
|
---|
477 |
|
---|
478 | this.muteAll = function() {
|
---|
479 | _s.mute();
|
---|
480 | };
|
---|
481 |
|
---|
482 | this.unmute = function(sID) {
|
---|
483 | var fN = _sm+'.unmute(): ', i;
|
---|
484 | if (typeof sID !== 'string') {
|
---|
485 | sID = null;
|
---|
486 | }
|
---|
487 | if (!sID) {
|
---|
488 | _s._wD(fN + 'Unmuting all sounds');
|
---|
489 | for (i = _s.soundIDs.length; i--;) {
|
---|
490 | _s.sounds[_s.soundIDs[i]].unmute();
|
---|
491 | }
|
---|
492 | _s.muted = false;
|
---|
493 | } else {
|
---|
494 | if (!_idCheck(sID)) {
|
---|
495 | return false;
|
---|
496 | }
|
---|
497 | _s._wD(fN + 'Unmuting "' + sID + '"');
|
---|
498 | return _s.sounds[sID].unmute();
|
---|
499 | }
|
---|
500 | return true;
|
---|
501 | };
|
---|
502 |
|
---|
503 | this.unmuteAll = function() {
|
---|
504 | _s.unmute();
|
---|
505 | };
|
---|
506 |
|
---|
507 | this.toggleMute = function(sID) {
|
---|
508 | if (!_idCheck(sID)) {
|
---|
509 | return false;
|
---|
510 | }
|
---|
511 | return _s.sounds[sID].toggleMute();
|
---|
512 | };
|
---|
513 |
|
---|
514 | this.getMemoryUse = function() {
|
---|
515 | // flash-only
|
---|
516 | var ram = 0;
|
---|
517 | if (_s.o && _fV !== 8) {
|
---|
518 | ram = parseInt(_s.o._getMemoryUse(), 10);
|
---|
519 | }
|
---|
520 | return ram;
|
---|
521 | };
|
---|
522 |
|
---|
523 | this.disable = function(bNoDisable) {
|
---|
524 | // destroy all functions
|
---|
525 | var i;
|
---|
526 | if (typeof bNoDisable === 'undefined') {
|
---|
527 | bNoDisable = false;
|
---|
528 | }
|
---|
529 | if (_disabled) {
|
---|
530 | return false;
|
---|
531 | }
|
---|
532 | _disabled = true;
|
---|
533 | _wDS('shutdown', 1);
|
---|
534 | for (i = _s.soundIDs.length; i--;) {
|
---|
535 | _disableObject(_s.sounds[_s.soundIDs[i]]);
|
---|
536 | }
|
---|
537 | _initComplete(bNoDisable); // fire "complete", despite fail
|
---|
538 | _event.remove(_win, 'load', _initUserOnload);
|
---|
539 | return true;
|
---|
540 | };
|
---|
541 |
|
---|
542 | this.canPlayMIME = function(sMIME) {
|
---|
543 | var result;
|
---|
544 | if (_s.hasHTML5) {
|
---|
545 | result = _html5CanPlay({type:sMIME});
|
---|
546 | }
|
---|
547 | if (!_needsFlash || result) {
|
---|
548 | // no flash, or OK
|
---|
549 | return result;
|
---|
550 | } else {
|
---|
551 | return (sMIME?(sMIME.match(_s.mimePattern)?true:false):null);
|
---|
552 | }
|
---|
553 | };
|
---|
554 |
|
---|
555 | this.canPlayURL = function(sURL) {
|
---|
556 | var result;
|
---|
557 | if (_s.hasHTML5) {
|
---|
558 | result = _html5CanPlay({url: sURL});
|
---|
559 | }
|
---|
560 | if (!_needsFlash || result) {
|
---|
561 | // no flash, or OK
|
---|
562 | return result;
|
---|
563 | } else {
|
---|
564 | return (sURL?(sURL.match(_s.filePattern)?true:false):null);
|
---|
565 | }
|
---|
566 | };
|
---|
567 |
|
---|
568 | this.canPlayLink = function(oLink) {
|
---|
569 | if (typeof oLink.type !== 'undefined' && oLink.type) {
|
---|
570 | if (_s.canPlayMIME(oLink.type)) {
|
---|
571 | return true;
|
---|
572 | }
|
---|
573 | }
|
---|
574 | return _s.canPlayURL(oLink.href);
|
---|
575 | };
|
---|
576 |
|
---|
577 | this.getSoundById = function(sID, suppressDebug) {
|
---|
578 | if (!sID) {
|
---|
579 | throw new Error(_sm+'.getSoundById(): sID is null/undefined');
|
---|
580 | }
|
---|
581 | var result = _s.sounds[sID];
|
---|
582 | if (!result && !suppressDebug) {
|
---|
583 | _s._wD('"' + sID + '" is an invalid sound ID.', 2);
|
---|
584 | }
|
---|
585 | return result;
|
---|
586 | };
|
---|
587 |
|
---|
588 | this.onready = function(oMethod, oScope) {
|
---|
589 | var sType = 'onready';
|
---|
590 | if (oMethod && oMethod instanceof Function) {
|
---|
591 | if (_didInit) {
|
---|
592 | _s._wD(_str('queue', sType));
|
---|
593 | }
|
---|
594 | if (!oScope) {
|
---|
595 | oScope = _win;
|
---|
596 | }
|
---|
597 | _addOnEvent(sType, oMethod, oScope);
|
---|
598 | _processOnEvents();
|
---|
599 | return true;
|
---|
600 | } else {
|
---|
601 | throw _str('needFunction', sType);
|
---|
602 | }
|
---|
603 | };
|
---|
604 |
|
---|
605 | this.ontimeout = function(oMethod, oScope) {
|
---|
606 | var sType = 'ontimeout';
|
---|
607 | if (oMethod && oMethod instanceof Function) {
|
---|
608 | if (_didInit) {
|
---|
609 | _s._wD(_str('queue', sType));
|
---|
610 | }
|
---|
611 | if (!oScope) {
|
---|
612 | oScope = _win;
|
---|
613 | }
|
---|
614 | _addOnEvent(sType, oMethod, oScope);
|
---|
615 | _processOnEvents({type:sType});
|
---|
616 | return true;
|
---|
617 | } else {
|
---|
618 | throw _str('needFunction', sType);
|
---|
619 | }
|
---|
620 | };
|
---|
621 |
|
---|
622 | this._writeDebug = function(sText, sType, bTimestamp) {
|
---|
623 | // pseudo-private console.log()-style output
|
---|
624 | // <d>
|
---|
625 | var sDID = 'soundmanager-debug', o, oItem, sMethod;
|
---|
626 | if (!_s.debugMode) {
|
---|
627 | return false;
|
---|
628 | }
|
---|
629 | if (typeof bTimestamp !== 'undefined' && bTimestamp) {
|
---|
630 | sText = sText + ' | ' + new Date().getTime();
|
---|
631 | }
|
---|
632 | if (_hasConsole && _s.useConsole) {
|
---|
633 | sMethod = _debugLevels[sType];
|
---|
634 | if (typeof console[sMethod] !== 'undefined') {
|
---|
635 | console[sMethod](sText);
|
---|
636 | } else {
|
---|
637 | console.log(sText);
|
---|
638 | }
|
---|
639 | if (_s.useConsoleOnly) {
|
---|
640 | return true;
|
---|
641 | }
|
---|
642 | }
|
---|
643 | try {
|
---|
644 | o = _id(sDID);
|
---|
645 | if (!o) {
|
---|
646 | return false;
|
---|
647 | }
|
---|
648 | oItem = _doc.createElement('div');
|
---|
649 | if (++_wdCount % 2 === 0) {
|
---|
650 | oItem.className = 'sm2-alt';
|
---|
651 | }
|
---|
652 | if (typeof sType === 'undefined') {
|
---|
653 | sType = 0;
|
---|
654 | } else {
|
---|
655 | sType = parseInt(sType, 10);
|
---|
656 | }
|
---|
657 | oItem.appendChild(_doc.createTextNode(sText));
|
---|
658 | if (sType) {
|
---|
659 | if (sType >= 2) {
|
---|
660 | oItem.style.fontWeight = 'bold';
|
---|
661 | }
|
---|
662 | if (sType === 3) {
|
---|
663 | oItem.style.color = '#ff3333';
|
---|
664 | }
|
---|
665 | }
|
---|
666 | // o.appendChild(oItem); // top-to-bottom
|
---|
667 | o.insertBefore(oItem, o.firstChild); // bottom-to-top
|
---|
668 | } catch(e) {
|
---|
669 | // oh well
|
---|
670 | }
|
---|
671 | o = null;
|
---|
672 | // </d>
|
---|
673 | return true;
|
---|
674 | };
|
---|
675 | this._wD = this._writeDebug; // alias
|
---|
676 |
|
---|
677 | this._debug = function() {
|
---|
678 | // <d>
|
---|
679 | var i, j;
|
---|
680 | _wDS('currentObj', 1);
|
---|
681 | for (i = 0, j = _s.soundIDs.length; i < j; i++) {
|
---|
682 | _s.sounds[_s.soundIDs[i]]._debug();
|
---|
683 | }
|
---|
684 | // </d>
|
---|
685 | };
|
---|
686 |
|
---|
687 | this.reboot = function() {
|
---|
688 | // attempt to reset and init SM2
|
---|
689 | _s._wD(_sm+'.reboot()');
|
---|
690 | if (_s.soundIDs.length) {
|
---|
691 | _s._wD('Destroying ' + _s.soundIDs.length + ' SMSound objects...');
|
---|
692 | }
|
---|
693 | var i, j;
|
---|
694 | for (i = _s.soundIDs.length; i--;) {
|
---|
695 | _s.sounds[_s.soundIDs[i]].destruct();
|
---|
696 | }
|
---|
697 | // trash ze flash
|
---|
698 | try {
|
---|
699 | if (_isIE) {
|
---|
700 | _oRemovedHTML = _s.o.innerHTML;
|
---|
701 | }
|
---|
702 | _oRemoved = _s.o.parentNode.removeChild(_s.o);
|
---|
703 | _s._wD('Flash movie removed.');
|
---|
704 | } catch(e) {
|
---|
705 | // uh-oh.
|
---|
706 | _wDS('badRemove', 2);
|
---|
707 | }
|
---|
708 | // actually, force recreate of movie.
|
---|
709 | _oRemovedHTML = _oRemoved = _needsFlash = null;
|
---|
710 | _s.enabled = _didDCLoaded = _didInit = _waitingForEI = _initPending = _didAppend = _appendSuccess = _disabled = _s.swfLoaded = false;
|
---|
711 | _s.soundIDs = _s.sounds = [];
|
---|
712 | _s.o = null;
|
---|
713 | for (i in _on_queue) {
|
---|
714 | if (_on_queue.hasOwnProperty(i)) {
|
---|
715 | for (j = _on_queue[i].length; j--;) {
|
---|
716 | _on_queue[i][j].fired = false;
|
---|
717 | }
|
---|
718 | }
|
---|
719 | }
|
---|
720 | _s._wD(_sm + ': Rebooting...');
|
---|
721 | _win.setTimeout(_s.beginDelayedInit, 20);
|
---|
722 | };
|
---|
723 |
|
---|
724 | this.getMoviePercent = function() {
|
---|
725 | return (_s.o && typeof _s.o.PercentLoaded !== 'undefined' ? _s.o.PercentLoaded() : null);
|
---|
726 | };
|
---|
727 |
|
---|
728 | this.beginDelayedInit = function() {
|
---|
729 | _windowLoaded = true;
|
---|
730 | _dcLoaded();
|
---|
731 | setTimeout(function() {
|
---|
732 | if (_initPending) {
|
---|
733 | return false;
|
---|
734 | }
|
---|
735 | _createMovie();
|
---|
736 | _initMovie();
|
---|
737 | _initPending = true;
|
---|
738 | return true;
|
---|
739 | }, 20);
|
---|
740 | _delayWaitForEI();
|
---|
741 | };
|
---|
742 |
|
---|
743 | this.destruct = function() {
|
---|
744 | _s._wD(_sm+'.destruct()');
|
---|
745 | _s.disable(true);
|
---|
746 | };
|
---|
747 |
|
---|
748 | /*
|
---|
749 | * internal HTML5 event handling
|
---|
750 | */
|
---|
751 |
|
---|
752 | function _html5_event(oFn) {
|
---|
753 | // wrap html5 event handlers so we don't call them on destroyed sounds
|
---|
754 | return function(e) {
|
---|
755 | if (!this._t || !this._t._a) {
|
---|
756 | if (this._t && this._t.sID) {
|
---|
757 | _s._wD(_h5+'ignoring '+e.type+': '+this._t.sID);
|
---|
758 | } else {
|
---|
759 | _s._wD(_h5+'ignoring '+e.type);
|
---|
760 | }
|
---|
761 | return null;
|
---|
762 | } else {
|
---|
763 | return oFn.call(this, e);
|
---|
764 | }
|
---|
765 | };
|
---|
766 | }
|
---|
767 |
|
---|
768 | _html5_events = {
|
---|
769 |
|
---|
770 | // HTML5 event-name-to-handler map
|
---|
771 | abort: _html5_event(function(e) {
|
---|
772 | _s._wD(_h5+'abort: '+this._t.sID);
|
---|
773 | }),
|
---|
774 |
|
---|
775 | // enough has loaded to play
|
---|
776 | canplay: _html5_event(function(e) {
|
---|
777 | if (this._t._html5_canplay) {
|
---|
778 | // this event has already fired. ignore.
|
---|
779 | return true;
|
---|
780 | }
|
---|
781 | this._t._html5_canplay = true;
|
---|
782 | _s._wD(_h5+'canplay: '+this._t.sID+', '+this._t.url);
|
---|
783 | this._t._onbufferchange(0);
|
---|
784 | var position1K = (!isNaN(this._t.position)?this._t.position/1000:null);
|
---|
785 | // set the position if position was set before the sound loaded
|
---|
786 | if (this._t.position && this.currentTime !== position1K) {
|
---|
787 | _s._wD(_h5+'canplay: setting position to '+position1K);
|
---|
788 | try {
|
---|
789 | this.currentTime = position1K;
|
---|
790 | } catch(ee) {
|
---|
791 | _s._wD(_h5+'setting position failed: '+ee.message, 2);
|
---|
792 | }
|
---|
793 | }
|
---|
794 | }),
|
---|
795 |
|
---|
796 | load: _html5_event(function(e) {
|
---|
797 | if (!this._t.loaded) {
|
---|
798 | this._t._onbufferchange(0);
|
---|
799 | // should be 1, and the same
|
---|
800 | this._t._whileloading(this._t.bytesTotal, this._t.bytesTotal, this._t._get_html5_duration());
|
---|
801 | this._t._onload(true);
|
---|
802 | }
|
---|
803 | }),
|
---|
804 |
|
---|
805 | emptied: _html5_event(function(e) {
|
---|
806 | _s._wD(_h5+'emptied: '+this._t.sID);
|
---|
807 | }),
|
---|
808 |
|
---|
809 | ended: _html5_event(function(e) {
|
---|
810 | _s._wD(_h5+'ended: '+this._t.sID);
|
---|
811 | this._t._onfinish();
|
---|
812 | }),
|
---|
813 |
|
---|
814 | error: _html5_event(function(e) {
|
---|
815 | _s._wD(_h5+'error: '+this.error.code);
|
---|
816 | // call load with error state?
|
---|
817 | this._t._onload(false);
|
---|
818 | }),
|
---|
819 |
|
---|
820 | loadeddata: _html5_event(function(e) {
|
---|
821 | var t = this._t,
|
---|
822 | bytesTotal = t.bytesTotal || 1; // at least 1 byte, so math works
|
---|
823 | _s._wD(_h5+'loadeddata: '+this._t.sID);
|
---|
824 | if (!t._loaded && !_isSafari) { // safari seems to nicely report progress events, eventually totalling 100%
|
---|
825 | t.duration = t._get_html5_duration();
|
---|
826 | // fire whileloading() with 100% values
|
---|
827 | t._whileloading(bytesTotal, bytesTotal, t._get_html5_duration());
|
---|
828 | t._onload(true);
|
---|
829 | }
|
---|
830 | }),
|
---|
831 |
|
---|
832 | loadedmetadata: _html5_event(function(e) {
|
---|
833 | _s._wD(_h5+'loadedmetadata: '+this._t.sID);
|
---|
834 | }),
|
---|
835 |
|
---|
836 | loadstart: _html5_event(function(e) {
|
---|
837 | _s._wD(_h5+'loadstart: '+this._t.sID);
|
---|
838 | // assume buffering at first
|
---|
839 | this._t._onbufferchange(1);
|
---|
840 | }),
|
---|
841 |
|
---|
842 | play: _html5_event(function(e) {
|
---|
843 | _s._wD(_h5+'play: '+this._t.sID+', '+this._t.url);
|
---|
844 | // once play starts, no buffering
|
---|
845 | this._t._onbufferchange(0);
|
---|
846 | }),
|
---|
847 |
|
---|
848 | // TODO: verify if this is actually implemented anywhere yet.
|
---|
849 | playing: _html5_event(function(e) {
|
---|
850 | _s._wD(_h5+'playing: '+this._t.sID+', '+this._t.url);
|
---|
851 | // once play starts, no buffering
|
---|
852 | this._t._onbufferchange(0);
|
---|
853 | }),
|
---|
854 |
|
---|
855 | progress: _html5_event(function(e) {
|
---|
856 |
|
---|
857 | if (this._t.loaded) {
|
---|
858 | return false;
|
---|
859 | }
|
---|
860 |
|
---|
861 | var i, j, str, buffered = 0,
|
---|
862 | isProgress = (e.type === 'progress'),
|
---|
863 | ranges = e.target.buffered,
|
---|
864 | loaded = (e.loaded||0), // firefox 3.6 implements e.loaded/total (bytes)
|
---|
865 | total = (e.total||1);
|
---|
866 |
|
---|
867 | if (ranges && ranges.length) {
|
---|
868 |
|
---|
869 | // if loaded is 0, try TimeRanges implementation as % of load
|
---|
870 | // https://developer.mozilla.org/en/DOM/TimeRanges
|
---|
871 | for (i=ranges.length; i--;) {
|
---|
872 | buffered = (ranges.end(i) - ranges.start(i));
|
---|
873 | }
|
---|
874 |
|
---|
875 | // linear case, buffer sum; does not account for seeking and HTTP partials / byte ranges
|
---|
876 | loaded = buffered/e.target.duration;
|
---|
877 |
|
---|
878 | // <d>
|
---|
879 | if (isProgress && ranges.length > 1) {
|
---|
880 | str = [];
|
---|
881 | j = ranges.length;
|
---|
882 | for (i=0; i<j; i++) {
|
---|
883 | str.push(e.target.buffered.start(i) +'-'+ e.target.buffered.end(i));
|
---|
884 | }
|
---|
885 | _s._wD(_h5+'progress: timeRanges: '+str.join(', '));
|
---|
886 | }
|
---|
887 | // </d>
|
---|
888 |
|
---|
889 | if (isProgress && !isNaN(loaded)) {
|
---|
890 | _s._wD(_h5+'progress: '+this._t.sID+': ' + Math.floor(loaded*100)+'% loaded');
|
---|
891 | }
|
---|
892 |
|
---|
893 | }
|
---|
894 |
|
---|
895 | if (!isNaN(loaded)) {
|
---|
896 |
|
---|
897 | this._t._onbufferchange(0); // if progress, likely not buffering
|
---|
898 | this._t._whileloading(loaded, total, this._t._get_html5_duration());
|
---|
899 |
|
---|
900 | if (loaded && total && loaded === total) {
|
---|
901 | // in case "onload" doesn't fire (eg. gecko 1.9.2)
|
---|
902 | _html5_events.load.call(this, e);
|
---|
903 | }
|
---|
904 |
|
---|
905 | }
|
---|
906 |
|
---|
907 | }),
|
---|
908 |
|
---|
909 | ratechange: _html5_event(function(e) {
|
---|
910 | _s._wD(_h5+'ratechange: '+this._t.sID);
|
---|
911 | }),
|
---|
912 |
|
---|
913 | suspend: _html5_event(function(e) {
|
---|
914 | // download paused/stopped, may have finished (eg. onload)
|
---|
915 | _s._wD(_h5+'suspend: '+this._t.sID);
|
---|
916 | _html5_events.progress.call(this, e);
|
---|
917 | }),
|
---|
918 |
|
---|
919 | stalled: _html5_event(function(e) {
|
---|
920 | _s._wD(_h5+'stalled: '+this._t.sID);
|
---|
921 | }),
|
---|
922 |
|
---|
923 | timeupdate: _html5_event(function(e) {
|
---|
924 | this._t._onTimer();
|
---|
925 | }),
|
---|
926 |
|
---|
927 | waiting: _html5_event(function(e) { // see also: seeking
|
---|
928 | _s._wD(_h5+'waiting: '+this._t.sID);
|
---|
929 | // playback faster than download rate, etc.
|
---|
930 | this._t._onbufferchange(1);
|
---|
931 | })
|
---|
932 |
|
---|
933 | };
|
---|
934 |
|
---|
935 | /*
|
---|
936 | * SMSound() (sound object) instance
|
---|
937 | */
|
---|
938 |
|
---|
939 | SMSound = function(oOptions) {
|
---|
940 |
|
---|
941 | var _t = this, _resetProperties, _stop_html5_timer, _start_html5_timer;
|
---|
942 | this.sID = oOptions.id;
|
---|
943 | this.url = oOptions.url;
|
---|
944 | this.options = _mixin(oOptions);
|
---|
945 | this.instanceOptions = this.options; // per-play-instance-specific options
|
---|
946 | this._iO = this.instanceOptions; // short alias
|
---|
947 | // assign property defaults
|
---|
948 | this.pan = this.options.pan;
|
---|
949 | this.volume = this.options.volume;
|
---|
950 | this._lastURL = null;
|
---|
951 | this.isHTML5 = false;
|
---|
952 | this._a = null;
|
---|
953 |
|
---|
954 | // --- public methods ---
|
---|
955 |
|
---|
956 | this.id3 = {};
|
---|
957 |
|
---|
958 | this._debug = function() {
|
---|
959 | // <d>
|
---|
960 | // pseudo-private console.log()-style output
|
---|
961 | if (_s.debugMode) {
|
---|
962 | var stuff = null, msg = [], sF, sfBracket, maxLength = 64;
|
---|
963 | for (stuff in _t.options) {
|
---|
964 | if (_t.options[stuff] !== null) {
|
---|
965 | if (_t.options[stuff] instanceof Function) {
|
---|
966 | // handle functions specially
|
---|
967 | sF = _t.options[stuff].toString();
|
---|
968 | sF = sF.replace(/\s\s+/g, ' '); // normalize spaces
|
---|
969 | sfBracket = sF.indexOf('{');
|
---|
970 | msg.push(' ' + stuff + ': {' + sF.substr(sfBracket + 1, (Math.min(Math.max(sF.indexOf('\n') - 1, maxLength), maxLength))).replace(/\n/g, '') + '... }');
|
---|
971 | } else {
|
---|
972 | msg.push(' ' + stuff + ': ' + _t.options[stuff]);
|
---|
973 | }
|
---|
974 | }
|
---|
975 | }
|
---|
976 | _s._wD('SMSound() merged options: {\n' + msg.join(', \n') + '\n}');
|
---|
977 | }
|
---|
978 | // </d>
|
---|
979 | };
|
---|
980 |
|
---|
981 | // <d>
|
---|
982 | this._debug();
|
---|
983 | // </d>
|
---|
984 |
|
---|
985 | this.load = function(oOptions) {
|
---|
986 | var oS = null;
|
---|
987 | if (typeof oOptions !== 'undefined') {
|
---|
988 | _t._iO = _mixin(oOptions, _t.options);
|
---|
989 | _t.instanceOptions = _t._iO;
|
---|
990 | } else {
|
---|
991 | oOptions = _t.options;
|
---|
992 | _t._iO = oOptions;
|
---|
993 | _t.instanceOptions = _t._iO;
|
---|
994 | if (_t._lastURL && _t._lastURL !== _t.url) {
|
---|
995 | _wDS('manURL');
|
---|
996 | _t._iO.url = _t.url;
|
---|
997 | _t.url = null;
|
---|
998 | }
|
---|
999 | }
|
---|
1000 | if (!_t._iO.url) {
|
---|
1001 | _t._iO.url = _t.url;
|
---|
1002 | }
|
---|
1003 | _s._wD('SMSound.load(): ' + _t._iO.url, 1);
|
---|
1004 | if (_t._iO.url === _t.url && _t.readyState !== 0 && _t.readyState !== 2) {
|
---|
1005 | _wDS('onURL', 1);
|
---|
1006 | return _t;
|
---|
1007 | }
|
---|
1008 | _t._lastURL = _t.url;
|
---|
1009 | _t.loaded = false;
|
---|
1010 | _t.readyState = 1;
|
---|
1011 | _t.playState = 0;
|
---|
1012 | if (_html5OK(_t._iO)) {
|
---|
1013 | oS = _t._setup_html5(_t._iO);
|
---|
1014 | if (!oS._called_load) {
|
---|
1015 | _s._wD(_h5+'load: '+_t.sID);
|
---|
1016 | _t._html5_canplay = false;
|
---|
1017 | oS.load();
|
---|
1018 | oS._called_load = true;
|
---|
1019 | if (_t._iO.autoPlay) {
|
---|
1020 | _t.play();
|
---|
1021 | }
|
---|
1022 | } else {
|
---|
1023 | _s._wD(_h5+'ignoring request to load again: '+_t.sID);
|
---|
1024 | }
|
---|
1025 | } else {
|
---|
1026 | try {
|
---|
1027 | _t.isHTML5 = false;
|
---|
1028 | _t._iO = _policyFix(_loopFix(_t._iO));
|
---|
1029 | if (_fV === 8) {
|
---|
1030 | _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);
|
---|
1031 | } else {
|
---|
1032 | _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);
|
---|
1033 | }
|
---|
1034 | } catch(e) {
|
---|
1035 | _wDS('smError', 2);
|
---|
1036 | _debugTS('onload', false);
|
---|
1037 | _catchError({type:'SMSOUND_LOAD_JS_EXCEPTION', fatal:true});
|
---|
1038 | }
|
---|
1039 | }
|
---|
1040 | return _t;
|
---|
1041 | };
|
---|
1042 |
|
---|
1043 | this.unload = function() {
|
---|
1044 | // Flash 8/AS2 can't "close" a stream - fake it by loading an empty MP3
|
---|
1045 | // Flash 9/AS3: Close stream, preventing further load
|
---|
1046 | if (_t.readyState !== 0) {
|
---|
1047 | _s._wD('SMSound.unload(): "' + _t.sID + '"');
|
---|
1048 | if (!_t.isHTML5) {
|
---|
1049 | if (_fV === 8) {
|
---|
1050 | _s.o._unload(_t.sID, _s.nullURL);
|
---|
1051 | } else {
|
---|
1052 | _s.o._unload(_t.sID);
|
---|
1053 | }
|
---|
1054 | } else {
|
---|
1055 | _stop_html5_timer();
|
---|
1056 | if (_t._a) {
|
---|
1057 | // abort()-style method here, stop loading? (doesn't exist?)
|
---|
1058 | _t._a.pause();
|
---|
1059 | _t._a.src = ''; // https://developer.mozilla.org/En/Using_audio_and_video_in_Firefox#Stopping_the_download_of_media
|
---|
1060 | }
|
---|
1061 | }
|
---|
1062 | // reset load/status flags
|
---|
1063 | _resetProperties();
|
---|
1064 | }
|
---|
1065 | return _t;
|
---|
1066 | };
|
---|
1067 |
|
---|
1068 | this.destruct = function(_bFromSM) {
|
---|
1069 | _s._wD('SMSound.destruct(): "' + _t.sID + '"');
|
---|
1070 | if (!_t.isHTML5) {
|
---|
1071 | // kill sound within Flash
|
---|
1072 | // Disable the onfailure handler
|
---|
1073 | _t._iO.onfailure = null;
|
---|
1074 | _s.o._destroySound(_t.sID);
|
---|
1075 | } else {
|
---|
1076 | _stop_html5_timer();
|
---|
1077 | if (_t._a) {
|
---|
1078 | // abort()-style method here, stop loading? (doesn't exist?)
|
---|
1079 | _t._a.pause();
|
---|
1080 | _t._a.src = ''; // https://developer.mozilla.org/En/Using_audio_and_video_in_Firefox#Stopping_the_download_of_media
|
---|
1081 | if (!_useGlobalHTML5Audio) {
|
---|
1082 | _t._remove_html5_events();
|
---|
1083 | }
|
---|
1084 | _t._a._t = null; // break potential circular reference
|
---|
1085 | _t._a = null;
|
---|
1086 | }
|
---|
1087 | }
|
---|
1088 | if (!_bFromSM) {
|
---|
1089 | _s.destroySound(_t.sID, true); // ensure deletion from controller
|
---|
1090 | }
|
---|
1091 | };
|
---|
1092 |
|
---|
1093 | this.play = function(oOptions, _updatePlayState) {
|
---|
1094 | var fN = 'SMSound.play(): ', allowMulti, a;
|
---|
1095 | _updatePlayState = _updatePlayState === undefined ? true : _updatePlayState; // default to true
|
---|
1096 | if (!oOptions) {
|
---|
1097 | oOptions = {};
|
---|
1098 | }
|
---|
1099 | _t._iO = _mixin(oOptions, _t._iO);
|
---|
1100 | _t._iO = _mixin(_t._iO, _t.options);
|
---|
1101 | _t.instanceOptions = _t._iO;
|
---|
1102 | if (_t._iO.serverURL && !_t.connected) {
|
---|
1103 | if (!_t.getAutoPlay()) {
|
---|
1104 | _s._wD(fN+' Netstream not connected yet - setting autoPlay');
|
---|
1105 | _t.setAutoPlay(true);
|
---|
1106 | }
|
---|
1107 | return _t; // play will be called in _onconnect()
|
---|
1108 | }
|
---|
1109 | if (_html5OK(_t._iO)) {
|
---|
1110 | _t._setup_html5(_t._iO);
|
---|
1111 | _start_html5_timer();
|
---|
1112 | }
|
---|
1113 | if (_t.playState === 1 && !_t.paused) {
|
---|
1114 | allowMulti = _t._iO.multiShot;
|
---|
1115 | if (!allowMulti) {
|
---|
1116 | _s._wD(fN + '"' + _t.sID + '" already playing (one-shot)', 1);
|
---|
1117 | return _t;
|
---|
1118 | } else {
|
---|
1119 | _s._wD(fN + '"' + _t.sID + '" already playing (multi-shot)', 1);
|
---|
1120 | }
|
---|
1121 | }
|
---|
1122 | if (!_t.loaded) {
|
---|
1123 | if (_t.readyState === 0) {
|
---|
1124 | _s._wD(fN + 'Attempting to load "' + _t.sID + '"', 1);
|
---|
1125 | // try to get this sound playing ASAP
|
---|
1126 | if (!_t.isHTML5) {
|
---|
1127 | _t._iO.autoPlay = true; // assign directly because setAutoPlay() increments the instanceCount
|
---|
1128 | }
|
---|
1129 | _t.load(_t._iO);
|
---|
1130 | } else if (_t.readyState === 2) {
|
---|
1131 | _s._wD(fN + 'Could not load "' + _t.sID + '" - exiting', 2);
|
---|
1132 | return _t;
|
---|
1133 | } else {
|
---|
1134 | _s._wD(fN + '"' + _t.sID + '" is loading - attempting to play..', 1);
|
---|
1135 | }
|
---|
1136 | } else {
|
---|
1137 | _s._wD(fN + '"' + _t.sID + '"');
|
---|
1138 | }
|
---|
1139 | if (!_t.isHTML5 && _fV === 9 && _t.position > 0 && _t.position === _t.duration) {
|
---|
1140 | // flash 9 needs a position reset if play() is called while at the end of a sound.
|
---|
1141 | _s._wD(fN + '"' + _t.sID + '": Sound at end, resetting to position:0');
|
---|
1142 | _t._iO.position = 0;
|
---|
1143 | }
|
---|
1144 | /*
|
---|
1145 | * Streams will pause when their buffer is full if they are being loaded.
|
---|
1146 | * In this case paused is true, but the song hasn't started playing yet.
|
---|
1147 | * If we just call resume() the onplay() callback will never be called.
|
---|
1148 | * So only call resume() if the position is > 0.
|
---|
1149 | * Another reason is because options like volume won't have been applied yet.
|
---|
1150 | */
|
---|
1151 | if (_t.paused && _t.position && _t.position > 0) { // https://gist.github.com/37b17df75cc4d7a90bf6
|
---|
1152 | _s._wD(fN + '"' + _t.sID + '" is resuming from paused state',1);
|
---|
1153 | _t.resume();
|
---|
1154 | } else {
|
---|
1155 | _s._wD(fN+'"'+ _t.sID+'" is starting to play');
|
---|
1156 | _t.playState = 1;
|
---|
1157 | _t.paused = false;
|
---|
1158 | if (!_t.instanceCount || _t._iO.multiShotEvents || (!_t.isHTML5 && _fV > 8 && !_t.getAutoPlay())) {
|
---|
1159 | _t.instanceCount++;
|
---|
1160 | }
|
---|
1161 | _t.position = (typeof _t._iO.position !== 'undefined' && !isNaN(_t._iO.position)?_t._iO.position:0);
|
---|
1162 | if (!_t.isHTML5) {
|
---|
1163 | _t._iO = _policyFix(_loopFix(_t._iO));
|
---|
1164 | }
|
---|
1165 | if (_t._iO.onplay && _updatePlayState) {
|
---|
1166 | _t._iO.onplay.apply(_t);
|
---|
1167 | _t._onplay_called = true;
|
---|
1168 | }
|
---|
1169 | _t.setVolume(_t._iO.volume, true);
|
---|
1170 | _t.setPan(_t._iO.pan, true);
|
---|
1171 | if (!_t.isHTML5) {
|
---|
1172 | _s.o._start(_t.sID, _t._iO.loops || 1, (_fV === 9?_t._iO.position:_t._iO.position / 1000));
|
---|
1173 | } else {
|
---|
1174 | _start_html5_timer();
|
---|
1175 | a = _t._setup_html5();
|
---|
1176 | _t.setPosition(_t._iO.position);
|
---|
1177 | a.play();
|
---|
1178 | }
|
---|
1179 | }
|
---|
1180 | return _t;
|
---|
1181 | };
|
---|
1182 |
|
---|
1183 | this.start = this.play; // just for convenience
|
---|
1184 |
|
---|
1185 | this.stop = function(bAll) {
|
---|
1186 | if (_t.playState === 1) {
|
---|
1187 | _t._onbufferchange(0);
|
---|
1188 | _t.resetOnPosition(0);
|
---|
1189 | if (!_t.isHTML5) {
|
---|
1190 | _t.playState = 0;
|
---|
1191 | }
|
---|
1192 | _t.paused = false;
|
---|
1193 | if (_t._iO.onstop) {
|
---|
1194 | _t._iO.onstop.apply(_t);
|
---|
1195 | }
|
---|
1196 | if (!_t.isHTML5) {
|
---|
1197 | _s.o._stop(_t.sID, bAll);
|
---|
1198 | // hack for netStream: just unload
|
---|
1199 | if (_t._iO.serverURL) {
|
---|
1200 | _t.unload();
|
---|
1201 | }
|
---|
1202 | } else {
|
---|
1203 | if (_t._a) {
|
---|
1204 | _t.setPosition(0); // act like Flash, though
|
---|
1205 | _t._a.pause(); // html5 has no stop()
|
---|
1206 | _t.playState = 0;
|
---|
1207 | _t._onTimer(); // and update UI
|
---|
1208 | _stop_html5_timer();
|
---|
1209 | _t.unload();
|
---|
1210 | }
|
---|
1211 | }
|
---|
1212 | _t.instanceCount = 0;
|
---|
1213 | _t._iO = {};
|
---|
1214 | }
|
---|
1215 | return _t;
|
---|
1216 | };
|
---|
1217 |
|
---|
1218 | this.setAutoPlay = function(autoPlay) {
|
---|
1219 | _s._wD('sound '+_t.sID+' turned autoplay ' + (autoPlay ? 'on' : 'off'));
|
---|
1220 | _t._iO.autoPlay = autoPlay;
|
---|
1221 | if (!_t.isHTML5) {
|
---|
1222 | _s.o._setAutoPlay(_t.sID, autoPlay);
|
---|
1223 | if (autoPlay) {
|
---|
1224 | // only increment the instanceCount if the sound isn't loaded (TODO: verify RTMP)
|
---|
1225 | if (!_t.instanceCount && _t.readyState === 1) {
|
---|
1226 | _t.instanceCount++;
|
---|
1227 | _s._wD('sound '+_t.sID+' incremented instance count to '+_t.instanceCount);
|
---|
1228 | }
|
---|
1229 | }
|
---|
1230 | }
|
---|
1231 | };
|
---|
1232 |
|
---|
1233 | this.getAutoPlay = function() {
|
---|
1234 | return _t._iO.autoPlay;
|
---|
1235 | };
|
---|
1236 |
|
---|
1237 | this.setPosition = function(nMsecOffset) {
|
---|
1238 | if (nMsecOffset === undefined) {
|
---|
1239 | nMsecOffset = 0;
|
---|
1240 | }
|
---|
1241 | // Use the duration from the instance options, if we don't have a track duration yet.
|
---|
1242 | var original_pos, position, position1K,
|
---|
1243 | offset = (_t.isHTML5 ? Math.max(nMsecOffset,0) : Math.min(_t.duration || _t._iO.duration, Math.max(nMsecOffset, 0))); // position >= 0 and <= current available (loaded) duration
|
---|
1244 | original_pos = _t.position;
|
---|
1245 | _t.position = offset;
|
---|
1246 | position1K = _t.position/1000;
|
---|
1247 | _t.resetOnPosition(_t.position);
|
---|
1248 | _t._iO.position = offset;
|
---|
1249 | if (!_t.isHTML5) {
|
---|
1250 | position = (_fV === 9 ? _t.position : position1K);
|
---|
1251 | if (_t.readyState && _t.readyState !== 2) {
|
---|
1252 | _s.o._setPosition(_t.sID, position, (_t.paused || !_t.playState)); // if paused or not playing, will not resume (by playing)
|
---|
1253 | }
|
---|
1254 | } else if (_t._a) {
|
---|
1255 | // Set the position in the canplay handler if the sound is not ready yet
|
---|
1256 | if (_t._html5_canplay) {
|
---|
1257 | if (_t._a.currentTime !== position1K) {
|
---|
1258 | /*
|
---|
1259 | * DOM/JS errors/exceptions to watch out for:
|
---|
1260 | * if seek is beyond (loaded?) position, "DOM exception 11"
|
---|
1261 | * "INDEX_SIZE_ERR": DOM exception 1
|
---|
1262 | */
|
---|
1263 | _s._wD('setPosition('+position1K+'): setting position');
|
---|
1264 | try {
|
---|
1265 | _t._a.currentTime = position1K;
|
---|
1266 | if (_t.playState === 0 || _t.paused) {
|
---|
1267 | // allow seek without auto-play/resume
|
---|
1268 | _t._a.pause();
|
---|
1269 | }
|
---|
1270 | } catch(e) {
|
---|
1271 | _s._wD('setPosition('+position1K+'): setting position failed: '+e.message, 2);
|
---|
1272 | }
|
---|
1273 | }
|
---|
1274 | } else {
|
---|
1275 | _s._wD('setPosition('+position1K+'): delaying, sound not ready');
|
---|
1276 | }
|
---|
1277 | }
|
---|
1278 | if (_t.isHTML5) {
|
---|
1279 | if (_t.paused) { // if paused, refresh UI right away
|
---|
1280 | _t._onTimer(true); // force update
|
---|
1281 | }
|
---|
1282 | }
|
---|
1283 | return _t;
|
---|
1284 | };
|
---|
1285 |
|
---|
1286 | this.pause = function(bCallFlash) {
|
---|
1287 | if (_t.paused || (_t.playState === 0 && _t.readyState !== 1)) {
|
---|
1288 | return _t;
|
---|
1289 | }
|
---|
1290 | _s._wD('SMSound.pause()');
|
---|
1291 | _t.paused = true;
|
---|
1292 | if (!_t.isHTML5) {
|
---|
1293 | if (bCallFlash || bCallFlash === undefined) {
|
---|
1294 | _s.o._pause(_t.sID);
|
---|
1295 | }
|
---|
1296 | } else {
|
---|
1297 | _t._setup_html5().pause();
|
---|
1298 | _stop_html5_timer();
|
---|
1299 | }
|
---|
1300 | if (_t._iO.onpause) {
|
---|
1301 | _t._iO.onpause.apply(_t);
|
---|
1302 | }
|
---|
1303 | return _t;
|
---|
1304 | };
|
---|
1305 |
|
---|
1306 | /*
|
---|
1307 | * When auto-loaded streams pause on buffer full they have a playState of 0.
|
---|
1308 | * We need to make sure that the playState is set to 1 when these streams "resume".
|
---|
1309 | * When a paused stream is resumed, we need to trigger the onplay() callback if it
|
---|
1310 | * hasn't been called already. In this case since the sound is being played for the
|
---|
1311 | * first time, I think it's more appropriate to call onplay() rather than onresume().
|
---|
1312 | */
|
---|
1313 | this.resume = function() {
|
---|
1314 | if (!_t.paused) {
|
---|
1315 | return _t;
|
---|
1316 | }
|
---|
1317 | _s._wD('SMSound.resume()');
|
---|
1318 | _t.paused = false;
|
---|
1319 | _t.playState = 1;
|
---|
1320 | if (!_t.isHTML5) {
|
---|
1321 | if (_t._iO.isMovieStar) {
|
---|
1322 | // Bizarre Webkit bug (Chrome reported via 8tracks.com dudes): AAC content paused for 30+ seconds(?) will not resume without a reposition.
|
---|
1323 | _t.setPosition(_t.position);
|
---|
1324 | }
|
---|
1325 | _s.o._pause(_t.sID); // flash method is toggle-based (pause/resume)
|
---|
1326 | } else {
|
---|
1327 | _t._setup_html5().play();
|
---|
1328 | _start_html5_timer();
|
---|
1329 | }
|
---|
1330 | if (!_t._onplay_called && _t._iO.onplay) {
|
---|
1331 | _t._iO.onplay.apply(_t);
|
---|
1332 | _t._onplay_called = true;
|
---|
1333 | } else if (_t._iO.onresume) {
|
---|
1334 | _t._iO.onresume.apply(_t);
|
---|
1335 | }
|
---|
1336 | return _t;
|
---|
1337 | };
|
---|
1338 |
|
---|
1339 | this.togglePause = function() {
|
---|
1340 | _s._wD('SMSound.togglePause()');
|
---|
1341 | if (_t.playState === 0) {
|
---|
1342 | _t.play({
|
---|
1343 | position: (_fV === 9 && !_t.isHTML5 ? _t.position : _t.position / 1000)
|
---|
1344 | });
|
---|
1345 | return _t;
|
---|
1346 | }
|
---|
1347 | if (_t.paused) {
|
---|
1348 | _t.resume();
|
---|
1349 | } else {
|
---|
1350 | _t.pause();
|
---|
1351 | }
|
---|
1352 | return _t;
|
---|
1353 | };
|
---|
1354 |
|
---|
1355 | this.setPan = function(nPan, bInstanceOnly) {
|
---|
1356 | if (typeof nPan === 'undefined') {
|
---|
1357 | nPan = 0;
|
---|
1358 | }
|
---|
1359 | if (typeof bInstanceOnly === 'undefined') {
|
---|
1360 | bInstanceOnly = false;
|
---|
1361 | }
|
---|
1362 | if (!_t.isHTML5) {
|
---|
1363 | _s.o._setPan(_t.sID, nPan);
|
---|
1364 | } // else { no HTML5 pan? }
|
---|
1365 | _t._iO.pan = nPan;
|
---|
1366 | if (!bInstanceOnly) {
|
---|
1367 | _t.pan = nPan;
|
---|
1368 | _t.options.pan = nPan;
|
---|
1369 | }
|
---|
1370 | return _t;
|
---|
1371 | };
|
---|
1372 |
|
---|
1373 | this.setVolume = function(nVol, bInstanceOnly) {
|
---|
1374 | if (typeof nVol === 'undefined') {
|
---|
1375 | nVol = 100;
|
---|
1376 | }
|
---|
1377 | if (typeof bInstanceOnly === 'undefined') {
|
---|
1378 | bInstanceOnly = false;
|
---|
1379 | }
|
---|
1380 | if (!_t.isHTML5) {
|
---|
1381 | _s.o._setVolume(_t.sID, (_s.muted && !_t.muted) || _t.muted?0:nVol);
|
---|
1382 | } else if (_t._a) {
|
---|
1383 | _t._a.volume = Math.max(0, Math.min(1, nVol/100)); // valid range: 0-1
|
---|
1384 | }
|
---|
1385 | _t._iO.volume = nVol;
|
---|
1386 | if (!bInstanceOnly) {
|
---|
1387 | _t.volume = nVol;
|
---|
1388 | _t.options.volume = nVol;
|
---|
1389 | }
|
---|
1390 | return _t;
|
---|
1391 | };
|
---|
1392 |
|
---|
1393 | this.mute = function() {
|
---|
1394 | _t.muted = true;
|
---|
1395 | if (!_t.isHTML5) {
|
---|
1396 | _s.o._setVolume(_t.sID, 0);
|
---|
1397 | } else if (_t._a) {
|
---|
1398 | _t._a.muted = true;
|
---|
1399 | }
|
---|
1400 | return _t;
|
---|
1401 | };
|
---|
1402 |
|
---|
1403 | this.unmute = function() {
|
---|
1404 | _t.muted = false;
|
---|
1405 | var hasIO = typeof _t._iO.volume !== 'undefined';
|
---|
1406 | if (!_t.isHTML5) {
|
---|
1407 | _s.o._setVolume(_t.sID, hasIO?_t._iO.volume:_t.options.volume);
|
---|
1408 | } else if (_t._a) {
|
---|
1409 | _t._a.muted = false;
|
---|
1410 | }
|
---|
1411 | return _t;
|
---|
1412 | };
|
---|
1413 |
|
---|
1414 | this.toggleMute = function() {
|
---|
1415 | return (_t.muted?_t.unmute():_t.mute());
|
---|
1416 | };
|
---|
1417 |
|
---|
1418 | this.onposition = function(nPosition, oMethod, oScope) {
|
---|
1419 | // TODO: allow for ranges, too? eg. (nPosition instanceof Array)
|
---|
1420 | _t._onPositionItems.push({
|
---|
1421 | position: nPosition,
|
---|
1422 | method: oMethod,
|
---|
1423 | scope: (typeof oScope !== 'undefined'?oScope:_t),
|
---|
1424 | fired: false
|
---|
1425 | });
|
---|
1426 | return _t;
|
---|
1427 | };
|
---|
1428 |
|
---|
1429 | this.processOnPosition = function() {
|
---|
1430 | var i, item, j = _t._onPositionItems.length;
|
---|
1431 | if (!j || !_t.playState || _t._onPositionFired >= j) {
|
---|
1432 | return false;
|
---|
1433 | }
|
---|
1434 | for (i=j; i--;) {
|
---|
1435 | item = _t._onPositionItems[i];
|
---|
1436 | if (!item.fired && _t.position >= item.position) {
|
---|
1437 | item.method.apply(item.scope,[item.position]);
|
---|
1438 | item.fired = true;
|
---|
1439 | _s._onPositionFired++;
|
---|
1440 | }
|
---|
1441 | }
|
---|
1442 | return true;
|
---|
1443 | };
|
---|
1444 |
|
---|
1445 | this.resetOnPosition = function(nPosition) {
|
---|
1446 | // reset "fired" for items interested in this position
|
---|
1447 | var i, item, j = _t._onPositionItems.length;
|
---|
1448 | if (!j) {
|
---|
1449 | return false;
|
---|
1450 | }
|
---|
1451 | for (i=j; i--;) {
|
---|
1452 | item = _t._onPositionItems[i];
|
---|
1453 | if (item.fired && nPosition <= item.position) {
|
---|
1454 | item.fired = false;
|
---|
1455 | _s._onPositionFired--;
|
---|
1456 | }
|
---|
1457 | }
|
---|
1458 | return true;
|
---|
1459 | };
|
---|
1460 |
|
---|
1461 | /*
|
---|
1462 | * private internals
|
---|
1463 | */
|
---|
1464 |
|
---|
1465 | _start_html5_timer = function() {
|
---|
1466 | if (_t.isHTML5) {
|
---|
1467 | _startTimer(_t);
|
---|
1468 | }
|
---|
1469 | };
|
---|
1470 |
|
---|
1471 | _stop_html5_timer = function() {
|
---|
1472 | if (_t.isHTML5) {
|
---|
1473 | _stopTimer(_t);
|
---|
1474 | }
|
---|
1475 | };
|
---|
1476 |
|
---|
1477 | _resetProperties = function() {
|
---|
1478 | _t._onPositionItems = [];
|
---|
1479 | _t._onPositionFired = 0;
|
---|
1480 | _t._hasTimer = null;
|
---|
1481 | _t._onplay_called = false;
|
---|
1482 | _t._a = null;
|
---|
1483 | _t._html5_canplay = false;
|
---|
1484 | _t.bytesLoaded = null;
|
---|
1485 | _t.bytesTotal = null;
|
---|
1486 | _t.position = null;
|
---|
1487 | _t.duration = (_t._iO && _t._iO.duration?_t._iO.duration:null);
|
---|
1488 | _t.durationEstimate = null;
|
---|
1489 | _t.failures = 0;
|
---|
1490 | _t.loaded = false;
|
---|
1491 | _t.playState = 0;
|
---|
1492 | _t.paused = false;
|
---|
1493 | _t.readyState = 0; // 0 = uninitialised, 1 = loading, 2 = failed/error, 3 = loaded/success
|
---|
1494 | _t.muted = false;
|
---|
1495 | _t.didBeforeFinish = false;
|
---|
1496 | _t.didJustBeforeFinish = false;
|
---|
1497 | _t.isBuffering = false;
|
---|
1498 | _t.instanceOptions = {};
|
---|
1499 | _t.instanceCount = 0;
|
---|
1500 | _t.peakData = {
|
---|
1501 | left: 0,
|
---|
1502 | right: 0
|
---|
1503 | };
|
---|
1504 | _t.waveformData = {
|
---|
1505 | left: [],
|
---|
1506 | right: []
|
---|
1507 | };
|
---|
1508 | _t.eqData = []; // legacy: 1D array
|
---|
1509 | _t.eqData.left = [];
|
---|
1510 | _t.eqData.right = [];
|
---|
1511 | };
|
---|
1512 |
|
---|
1513 | _resetProperties();
|
---|
1514 |
|
---|
1515 | /*
|
---|
1516 | * pseudo-private SMSound internals
|
---|
1517 | */
|
---|
1518 |
|
---|
1519 | this._onTimer = function(bForce) {
|
---|
1520 | // HTML5-only _whileplaying() etc.
|
---|
1521 | var time, x = {};
|
---|
1522 | if (_t._hasTimer || bForce) {
|
---|
1523 | if (_t._a && (bForce || ((_t.playState > 0 || _t.readyState === 1) && !_t.paused))) { // TODO: May not need to track readyState (1 = loading)
|
---|
1524 | _t.duration = _t._get_html5_duration();
|
---|
1525 | _t.durationEstimate = _t.duration;
|
---|
1526 | time = _t._a.currentTime?_t._a.currentTime*1000:0;
|
---|
1527 | _t._whileplaying(time,x,x,x,x);
|
---|
1528 | return true;
|
---|
1529 | } else {
|
---|
1530 | _s._wD('_onTimer: Warn for "'+_t.sID+'": '+(!_t._a?'Could not find element. ':'')+(_t.playState === 0?'playState bad, 0?':'playState = '+_t.playState+', OK'));
|
---|
1531 | return false;
|
---|
1532 | }
|
---|
1533 | }
|
---|
1534 | };
|
---|
1535 |
|
---|
1536 | this._get_html5_duration = function() {
|
---|
1537 | var d = (_t._a ? _t._a.duration*1000 : (_t._iO ? _t._iO.duration : undefined)),
|
---|
1538 | result = (d && !isNaN(d) && d !== Infinity ? d : (_t._iO ? _t._iO.duration : null));
|
---|
1539 | return result;
|
---|
1540 | };
|
---|
1541 |
|
---|
1542 | this._setup_html5 = function(oOptions) {
|
---|
1543 | var _iO = _mixin(_t._iO, oOptions), d = decodeURI,
|
---|
1544 | _a = _useGlobalHTML5Audio ? _s._global_a : _t._a,
|
---|
1545 | _dURL = d(_iO.url),
|
---|
1546 | _oldIO = (_a && _a._t ? _a._t.instanceOptions : null);
|
---|
1547 | if (_a) {
|
---|
1548 | if (_a._t && _oldIO.url === _iO.url && (!_t._lastURL || (_t._lastURL === _oldIO.url))) {
|
---|
1549 | return _a; // same url, ignore request
|
---|
1550 | }
|
---|
1551 | _s._wD('setting new URL on existing object: ' + _dURL + (_t._lastURL ? ', old URL: ' + _t._lastURL : ''));
|
---|
1552 | /*
|
---|
1553 | * "First things first, I, Poppa.." (reset the previous state of the old sound, if playing)
|
---|
1554 | * Fixes case with devices that can only play one sound at a time
|
---|
1555 | * Otherwise, other sounds in mid-play will be terminated without warning and in a stuck state
|
---|
1556 | */
|
---|
1557 | if (_useGlobalHTML5Audio && _a._t && _a._t.playState && _iO.url !== _oldIO.url) {
|
---|
1558 | _a._t.stop();
|
---|
1559 | }
|
---|
1560 | _resetProperties(); // new URL, so reset load/playstate and so on
|
---|
1561 | _a.src = _iO.url;
|
---|
1562 | _t.url = _iO.url;
|
---|
1563 | _t._lastURL = _iO.url;
|
---|
1564 | _a._called_load = false;
|
---|
1565 | } else {
|
---|
1566 | _s._wD('creating HTML5 Audio() element with URL: '+_dURL);
|
---|
1567 | _a = new Audio(_iO.url);
|
---|
1568 | _a._called_load = false;
|
---|
1569 | if (_useGlobalHTML5Audio) {
|
---|
1570 | _s._global_a = _a;
|
---|
1571 | }
|
---|
1572 | }
|
---|
1573 | _t.isHTML5 = true;
|
---|
1574 | _t._a = _a; // store a ref on the track
|
---|
1575 | _a._t = _t; // store a ref on the audio
|
---|
1576 | _t._add_html5_events();
|
---|
1577 | _a.loop = (_iO.loops>1?'loop':'');
|
---|
1578 | if (_iO.autoLoad || _iO.autoPlay) {
|
---|
1579 | _a.autobuffer = 'auto'; // early HTML5 implementation (non-standard)
|
---|
1580 | _a.preload = 'auto'; // standard
|
---|
1581 | _t.load();
|
---|
1582 | _a._called_load = true;
|
---|
1583 | } else {
|
---|
1584 | _a.autobuffer = false; // early HTML5 implementation (non-standard)
|
---|
1585 | _a.preload = 'none'; // standard
|
---|
1586 | }
|
---|
1587 | _a.loop = (_iO.loops>1?'loop':''); // boolean instead of "loop", for webkit? - spec says string. http://www.w3.org/TR/html-markup/audio.html#audio.attrs.loop
|
---|
1588 | return _a;
|
---|
1589 | };
|
---|
1590 |
|
---|
1591 | this._add_html5_events = function() {
|
---|
1592 |
|
---|
1593 | if (_t._a._added_events) {
|
---|
1594 | return false;
|
---|
1595 | }
|
---|
1596 |
|
---|
1597 | var f;
|
---|
1598 |
|
---|
1599 | function add(oEvt, oFn, bCapture) {
|
---|
1600 | return _t._a ? _t._a.addEventListener(oEvt, oFn, bCapture||false) : null;
|
---|
1601 | }
|
---|
1602 |
|
---|
1603 | _s._wD(_h5+'adding event listeners: '+_t.sID);
|
---|
1604 | _t._a._added_events = true;
|
---|
1605 |
|
---|
1606 | for (f in _html5_events) {
|
---|
1607 | if (_html5_events.hasOwnProperty(f)) {
|
---|
1608 | add(f, _html5_events[f]);
|
---|
1609 | }
|
---|
1610 | }
|
---|
1611 |
|
---|
1612 | return true;
|
---|
1613 |
|
---|
1614 | };
|
---|
1615 |
|
---|
1616 | this._remove_html5_events = function() {
|
---|
1617 |
|
---|
1618 | // Remove event listeners
|
---|
1619 |
|
---|
1620 | var f;
|
---|
1621 |
|
---|
1622 | function remove(oEvt, oFn, bCapture) {
|
---|
1623 | return (_t._a ? _t._a.removeEventListener(oEvt, oFn, bCapture||false) : null);
|
---|
1624 | }
|
---|
1625 |
|
---|
1626 | _s._wD(_h5+'removing event listeners: '+_t.sID);
|
---|
1627 | _t._a._added_events = false;
|
---|
1628 |
|
---|
1629 | for (f in _html5_events) {
|
---|
1630 | if (_html5_events.hasOwnProperty(f)) {
|
---|
1631 | remove(f, _html5_events[f]);
|
---|
1632 | }
|
---|
1633 | }
|
---|
1634 |
|
---|
1635 | };
|
---|
1636 |
|
---|
1637 | /*
|
---|
1638 | * pseudo-private event internals
|
---|
1639 | */
|
---|
1640 |
|
---|
1641 | this._onload = function(nSuccess) {
|
---|
1642 | var fN = 'SMSound._onload(): ', loadOK = (nSuccess?true:false);
|
---|
1643 | _s._wD(fN + '"' + _t.sID + '"' + (loadOK?' loaded.':' failed to load? - ' + _t.url), (loadOK?1:2));
|
---|
1644 | // <d>
|
---|
1645 | if (!loadOK && !_t.isHTML5) {
|
---|
1646 | if (_s.sandbox.noRemote === true) {
|
---|
1647 | _s._wD(fN + _str('noNet'), 1);
|
---|
1648 | }
|
---|
1649 | if (_s.sandbox.noLocal === true) {
|
---|
1650 | _s._wD(fN + _str('noLocal'), 1);
|
---|
1651 | }
|
---|
1652 | }
|
---|
1653 | // </d>
|
---|
1654 | _t.loaded = loadOK;
|
---|
1655 | _t.readyState = loadOK?3:2;
|
---|
1656 | _t._onbufferchange(0);
|
---|
1657 | if (_t._iO.onload) {
|
---|
1658 | _t._iO.onload.apply(_t, [loadOK]);
|
---|
1659 | }
|
---|
1660 | return true;
|
---|
1661 | };
|
---|
1662 |
|
---|
1663 | this._onbufferchange = function(nIsBuffering) {
|
---|
1664 | var fN = 'SMSound._onbufferchange()';
|
---|
1665 | if (_t.playState === 0) {
|
---|
1666 | // ignore if not playing
|
---|
1667 | return false;
|
---|
1668 | }
|
---|
1669 | if ((nIsBuffering && _t.isBuffering) || (!nIsBuffering && !_t.isBuffering)) {
|
---|
1670 | return false;
|
---|
1671 | }
|
---|
1672 | _t.isBuffering = (nIsBuffering === 1);
|
---|
1673 | if (_t._iO.onbufferchange) {
|
---|
1674 | _s._wD(fN + ': ' + nIsBuffering);
|
---|
1675 | _t._iO.onbufferchange.apply(_t);
|
---|
1676 | }
|
---|
1677 | return true;
|
---|
1678 | };
|
---|
1679 |
|
---|
1680 | /*
|
---|
1681 | * flash-only method, should fire only once at most
|
---|
1682 | * at this point we just recreate failed sounds rather than trying to reconnect
|
---|
1683 | */
|
---|
1684 | this._onfailure = function(msg, level, code) {
|
---|
1685 | _t.failures++;
|
---|
1686 | _s._wD('SMSound._onfailure(): "'+_t.sID+'" count '+_t.failures);
|
---|
1687 | if (_t._iO.onfailure && _t.failures === 1) {
|
---|
1688 | _t._iO.onfailure(_t, msg, level, code);
|
---|
1689 | } else {
|
---|
1690 | _s._wD('SMSound._onfailure(): ignoring');
|
---|
1691 | }
|
---|
1692 | };
|
---|
1693 |
|
---|
1694 | this._onbeforefinish = function() {
|
---|
1695 | if (!_t.didBeforeFinish) {
|
---|
1696 | _t.didBeforeFinish = true;
|
---|
1697 | if (_t._iO.onbeforefinish) {
|
---|
1698 | _s._wD('SMSound._onbeforefinish(): "' + _t.sID + '"');
|
---|
1699 | _t._iO.onbeforefinish.apply(_t);
|
---|
1700 | }
|
---|
1701 | }
|
---|
1702 | };
|
---|
1703 |
|
---|
1704 | this._onjustbeforefinish = function(msOffset) {
|
---|
1705 | if (!_t.didJustBeforeFinish) {
|
---|
1706 | _t.didJustBeforeFinish = true;
|
---|
1707 | if (_t._iO.onjustbeforefinish) {
|
---|
1708 | _s._wD('SMSound._onjustbeforefinish(): "' + _t.sID + '"');
|
---|
1709 | _t._iO.onjustbeforefinish.apply(_t);
|
---|
1710 | }
|
---|
1711 | }
|
---|
1712 | };
|
---|
1713 |
|
---|
1714 | this._onfinish = function() {
|
---|
1715 | var _io_onfinish = _t._iO.onfinish; // store local copy before it gets trashed..
|
---|
1716 | _t._onbufferchange(0);
|
---|
1717 | _t.resetOnPosition(0);
|
---|
1718 | if (_t._iO.onbeforefinishcomplete) {
|
---|
1719 | _t._iO.onbeforefinishcomplete.apply(_t);
|
---|
1720 | }
|
---|
1721 | // reset some state items
|
---|
1722 | _t.didBeforeFinish = false;
|
---|
1723 | _t.didJustBeforeFinish = false;
|
---|
1724 | if (_t.instanceCount) {
|
---|
1725 | _t.instanceCount--;
|
---|
1726 | if (!_t.instanceCount) {
|
---|
1727 | // reset instance options
|
---|
1728 | _t.playState = 0;
|
---|
1729 | _t.paused = false;
|
---|
1730 | _t.instanceCount = 0;
|
---|
1731 | _t.instanceOptions = {};
|
---|
1732 | _t._iO = {};
|
---|
1733 | _stop_html5_timer();
|
---|
1734 | }
|
---|
1735 | if (!_t.instanceCount || _t._iO.multiShotEvents) {
|
---|
1736 | // fire onfinish for last, or every instance
|
---|
1737 | if (_io_onfinish) {
|
---|
1738 | _s._wD('SMSound._onfinish(): "' + _t.sID + '"');
|
---|
1739 | _io_onfinish.apply(_t);
|
---|
1740 | }
|
---|
1741 | }
|
---|
1742 | }
|
---|
1743 | };
|
---|
1744 |
|
---|
1745 | this._whileloading = function(nBytesLoaded, nBytesTotal, nDuration, nBufferLength) {
|
---|
1746 | _t.bytesLoaded = nBytesLoaded;
|
---|
1747 | _t.bytesTotal = nBytesTotal;
|
---|
1748 | _t.duration = Math.floor(nDuration);
|
---|
1749 | _t.bufferLength = nBufferLength;
|
---|
1750 | if (!_t._iO.isMovieStar) {
|
---|
1751 | if (_t._iO.duration) {
|
---|
1752 | // use options, if specified and larger
|
---|
1753 | _t.durationEstimate = (_t.duration > _t._iO.duration) ? _t.duration : _t._iO.duration;
|
---|
1754 | } else {
|
---|
1755 | _t.durationEstimate = parseInt((_t.bytesTotal / _t.bytesLoaded) * _t.duration, 10);
|
---|
1756 | }
|
---|
1757 | if (_t.durationEstimate === undefined) {
|
---|
1758 | _t.durationEstimate = _t.duration;
|
---|
1759 | }
|
---|
1760 | if (_t.readyState !== 3 && _t._iO.whileloading) {
|
---|
1761 | _t._iO.whileloading.apply(_t);
|
---|
1762 | }
|
---|
1763 | } else {
|
---|
1764 | _t.durationEstimate = _t.duration;
|
---|
1765 | if (_t.readyState !== 3 && _t._iO.whileloading) {
|
---|
1766 | _t._iO.whileloading.apply(_t);
|
---|
1767 | }
|
---|
1768 | }
|
---|
1769 | };
|
---|
1770 |
|
---|
1771 | this._whileplaying = function(nPosition, oPeakData, oWaveformDataLeft, oWaveformDataRight, oEQData) {
|
---|
1772 | if (isNaN(nPosition) || nPosition === null) {
|
---|
1773 | return false; // flash safety net
|
---|
1774 | }
|
---|
1775 | _t.position = nPosition;
|
---|
1776 | _t.processOnPosition();
|
---|
1777 | if (!_t.isHTML5 && _fV > 8) {
|
---|
1778 | if (_t._iO.usePeakData && typeof oPeakData !== 'undefined' && oPeakData) {
|
---|
1779 | _t.peakData = {
|
---|
1780 | left: oPeakData.leftPeak,
|
---|
1781 | right: oPeakData.rightPeak
|
---|
1782 | };
|
---|
1783 | }
|
---|
1784 | if (_t._iO.useWaveformData && typeof oWaveformDataLeft !== 'undefined' && oWaveformDataLeft) {
|
---|
1785 | _t.waveformData = {
|
---|
1786 | left: oWaveformDataLeft.split(','),
|
---|
1787 | right: oWaveformDataRight.split(',')
|
---|
1788 | };
|
---|
1789 | }
|
---|
1790 | if (_t._iO.useEQData) {
|
---|
1791 | if (typeof oEQData !== 'undefined' && oEQData && oEQData.leftEQ) {
|
---|
1792 | var eqLeft = oEQData.leftEQ.split(',');
|
---|
1793 | _t.eqData = eqLeft;
|
---|
1794 | _t.eqData.left = eqLeft;
|
---|
1795 | if (typeof oEQData.rightEQ !== 'undefined' && oEQData.rightEQ) {
|
---|
1796 | _t.eqData.right = oEQData.rightEQ.split(',');
|
---|
1797 | }
|
---|
1798 | }
|
---|
1799 | }
|
---|
1800 | }
|
---|
1801 | if (_t.playState === 1) {
|
---|
1802 | // special case/hack: ensure buffering is false if loading from cache (and not yet started)
|
---|
1803 | if (!_t.isHTML5 && _s.flashVersion === 8 && !_t.position && _t.isBuffering) {
|
---|
1804 | _t._onbufferchange(0);
|
---|
1805 | }
|
---|
1806 | if (_t._iO.whileplaying) {
|
---|
1807 | _t._iO.whileplaying.apply(_t); // flash may call after actual finish
|
---|
1808 | }
|
---|
1809 | if ((_t.loaded || (!_t.loaded && _t._iO.isMovieStar)) && _t._iO.onbeforefinish && _t._iO.onbeforefinishtime && !_t.didBeforeFinish && _t.duration - _t.position <= _t._iO.onbeforefinishtime) {
|
---|
1810 | _t._onbeforefinish();
|
---|
1811 | }
|
---|
1812 | }
|
---|
1813 | return true;
|
---|
1814 | };
|
---|
1815 |
|
---|
1816 | this._onid3 = function(oID3PropNames, oID3Data) {
|
---|
1817 | // oID3PropNames: string array (names)
|
---|
1818 | // ID3Data: string array (data)
|
---|
1819 | _s._wD('SMSound._onid3(): "' + this.sID + '" ID3 data received.');
|
---|
1820 | var oData = [], i, j;
|
---|
1821 | for (i = 0, j = oID3PropNames.length; i < j; i++) {
|
---|
1822 | oData[oID3PropNames[i]] = oID3Data[i];
|
---|
1823 | }
|
---|
1824 | _t.id3 = _mixin(_t.id3, oData);
|
---|
1825 | if (_t._iO.onid3) {
|
---|
1826 | _t._iO.onid3.apply(_t);
|
---|
1827 | }
|
---|
1828 | };
|
---|
1829 |
|
---|
1830 | // flash + RTMP
|
---|
1831 | this._onconnect = function(bSuccess) {
|
---|
1832 | var fN = 'SMSound._onconnect(): ';
|
---|
1833 | bSuccess = (bSuccess === 1);
|
---|
1834 | _s._wD(fN+'"'+_t.sID+'"'+(bSuccess?' connected.':' failed to connect? - '+_t.url), (bSuccess?1:2));
|
---|
1835 | _t.connected = bSuccess;
|
---|
1836 | if (bSuccess) {
|
---|
1837 | _t.failures = 0;
|
---|
1838 | if (_idCheck(_t.sID)) {
|
---|
1839 | if (_t.getAutoPlay()) {
|
---|
1840 | _t.play(undefined, _t.getAutoPlay()); // only update the play state if auto playing
|
---|
1841 | } else if (_t._iO.autoLoad) {
|
---|
1842 | _t.load();
|
---|
1843 | }
|
---|
1844 | }
|
---|
1845 | if (_t._iO.onconnect) {
|
---|
1846 | _t._iO.onconnect.apply(_t,[bSuccess]);
|
---|
1847 | }
|
---|
1848 | }
|
---|
1849 | };
|
---|
1850 |
|
---|
1851 | this._ondataerror = function(sError) {
|
---|
1852 | // flash 9 wave/eq data handler
|
---|
1853 | if (_t.playState > 0) { // hack: called at start, and end from flash at/after onfinish()
|
---|
1854 | _s._wD('SMSound._ondataerror(): ' + sError);
|
---|
1855 | if (_t._iO.ondataerror) {
|
---|
1856 | _t._iO.ondataerror.apply(_t);
|
---|
1857 | }
|
---|
1858 | }
|
---|
1859 | };
|
---|
1860 |
|
---|
1861 | }; // SMSound()
|
---|
1862 |
|
---|
1863 | /*
|
---|
1864 | * private soundManager internals
|
---|
1865 | */
|
---|
1866 |
|
---|
1867 | _getDocument = function() {
|
---|
1868 | return (_doc.body || _doc._docElement || _doc.getElementsByTagName('div')[0]);
|
---|
1869 | };
|
---|
1870 |
|
---|
1871 | _id = function(sID) {
|
---|
1872 | return _doc.getElementById(sID);
|
---|
1873 | };
|
---|
1874 |
|
---|
1875 | _mixin = function(oMain, oAdd) {
|
---|
1876 | // non-destructive merge
|
---|
1877 | var o1 = {}, i, o2, o;
|
---|
1878 | for (i in oMain) { // clone c1
|
---|
1879 | if (oMain.hasOwnProperty(i)) {
|
---|
1880 | o1[i] = oMain[i];
|
---|
1881 | }
|
---|
1882 | }
|
---|
1883 | o2 = (typeof oAdd === 'undefined'?_s.defaultOptions:oAdd);
|
---|
1884 | for (o in o2) {
|
---|
1885 | if (o2.hasOwnProperty(o) && typeof o1[o] === 'undefined') {
|
---|
1886 | o1[o] = o2[o];
|
---|
1887 | }
|
---|
1888 | }
|
---|
1889 | return o1;
|
---|
1890 | };
|
---|
1891 |
|
---|
1892 | _event = (function() {
|
---|
1893 |
|
---|
1894 | var old = (_win.attachEvent),
|
---|
1895 | evt = {
|
---|
1896 | add: (old?'attachEvent':'addEventListener'),
|
---|
1897 | remove: (old?'detachEvent':'removeEventListener')
|
---|
1898 | };
|
---|
1899 |
|
---|
1900 | function getArgs(oArgs) {
|
---|
1901 | var args = _slice.call(oArgs), len = args.length;
|
---|
1902 | if (old) {
|
---|
1903 | args[1] = 'on' + args[1]; // prefix
|
---|
1904 | if (len > 3) {
|
---|
1905 | args.pop(); // no capture
|
---|
1906 | }
|
---|
1907 | } else if (len === 3) {
|
---|
1908 | args.push(false);
|
---|
1909 | }
|
---|
1910 | return args;
|
---|
1911 | }
|
---|
1912 |
|
---|
1913 | function apply(args, sType) {
|
---|
1914 | var element = args.shift(),
|
---|
1915 | method = [evt[sType]];
|
---|
1916 | if (old) {
|
---|
1917 | element[method](args[0], args[1]);
|
---|
1918 | } else {
|
---|
1919 | element[method].apply(element, args);
|
---|
1920 | }
|
---|
1921 | }
|
---|
1922 |
|
---|
1923 | function add() {
|
---|
1924 | apply(getArgs(arguments), 'add');
|
---|
1925 | }
|
---|
1926 |
|
---|
1927 | function remove() {
|
---|
1928 | apply(getArgs(arguments), 'remove');
|
---|
1929 | }
|
---|
1930 |
|
---|
1931 | return {
|
---|
1932 | 'add': add,
|
---|
1933 | 'remove': remove
|
---|
1934 | };
|
---|
1935 |
|
---|
1936 | }());
|
---|
1937 |
|
---|
1938 | _html5OK = function(iO) {
|
---|
1939 | return (!iO.serverURL && (iO.type?_html5CanPlay({type:iO.type}):_html5CanPlay({url:iO.url})||_s.html5Only)); // Use type, if specified. If HTML5-only mode, no other options, so just give 'er
|
---|
1940 | };
|
---|
1941 |
|
---|
1942 | _html5CanPlay = function(o) {
|
---|
1943 |
|
---|
1944 | /*
|
---|
1945 | * try to find MIME, test and return truthiness
|
---|
1946 | * o = {
|
---|
1947 | * url: '/path/to/an.mp3',
|
---|
1948 | * type: 'audio/mp3'
|
---|
1949 | * }
|
---|
1950 | */
|
---|
1951 |
|
---|
1952 | if (!_s.useHTML5Audio || !_s.hasHTML5) {
|
---|
1953 | return false;
|
---|
1954 | }
|
---|
1955 |
|
---|
1956 | var url = (o.url || null),
|
---|
1957 | mime = (o.type || null),
|
---|
1958 | aF = _s.audioFormats,
|
---|
1959 | result,
|
---|
1960 | offset,
|
---|
1961 | fileExt,
|
---|
1962 | item;
|
---|
1963 |
|
---|
1964 | function preferFlashCheck(kind) {
|
---|
1965 | // whether flash should play a given type
|
---|
1966 | return (_s.preferFlash && _hasFlash && !_s.ignoreFlash && (typeof _s.flash[kind] !== 'undefined' && _s.flash[kind]));
|
---|
1967 | }
|
---|
1968 |
|
---|
1969 | // account for known cases like audio/mp3
|
---|
1970 | if (mime && _s.html5[mime] !== 'undefined') {
|
---|
1971 | return (_s.html5[mime] && !preferFlashCheck(mime));
|
---|
1972 | }
|
---|
1973 |
|
---|
1974 | if (!_html5Ext) {
|
---|
1975 | _html5Ext = [];
|
---|
1976 | for (item in aF) {
|
---|
1977 | if (aF.hasOwnProperty(item)) {
|
---|
1978 | _html5Ext.push(item);
|
---|
1979 | if (aF[item].related) {
|
---|
1980 | _html5Ext = _html5Ext.concat(aF[item].related);
|
---|
1981 | }
|
---|
1982 | }
|
---|
1983 | }
|
---|
1984 | _html5Ext = new RegExp('\\.('+_html5Ext.join('|')+')(\\?.*)?$','i');
|
---|
1985 | }
|
---|
1986 |
|
---|
1987 | fileExt = (url ? url.toLowerCase().match(_html5Ext) : null); // TODO: Strip URL queries, etc.
|
---|
1988 |
|
---|
1989 | if (!fileExt || !fileExt.length) {
|
---|
1990 | if (!mime) {
|
---|
1991 | return false;
|
---|
1992 | } else {
|
---|
1993 | // audio/mp3 -> mp3, result should be known
|
---|
1994 | offset = mime.indexOf(';');
|
---|
1995 | fileExt = (offset !== -1?mime.substr(0,offset):mime).substr(6); // strip "audio/X; codecs.."
|
---|
1996 | }
|
---|
1997 | } else {
|
---|
1998 | fileExt = fileExt[1]; // match the raw extension name - "mp3", for example
|
---|
1999 | }
|
---|
2000 |
|
---|
2001 | if (fileExt && typeof _s.html5[fileExt] !== 'undefined') {
|
---|
2002 | // result known
|
---|
2003 | return (_s.html5[fileExt] && !preferFlashCheck(fileExt));
|
---|
2004 | } else {
|
---|
2005 | mime = 'audio/'+fileExt;
|
---|
2006 | result = _s.html5.canPlayType({type:mime});
|
---|
2007 | _s.html5[fileExt] = result;
|
---|
2008 | // _s._wD('canPlayType, found result: '+result);
|
---|
2009 | return (result && _s.html5[mime] && !preferFlashCheck(mime));
|
---|
2010 | }
|
---|
2011 |
|
---|
2012 | };
|
---|
2013 |
|
---|
2014 | _testHTML5 = function() {
|
---|
2015 |
|
---|
2016 | if (!_s.useHTML5Audio || typeof Audio === 'undefined') {
|
---|
2017 | return false;
|
---|
2018 | }
|
---|
2019 |
|
---|
2020 | // double-whammy: Opera 9.64 throws WRONG_ARGUMENTS_ERR if no parameter passed to Audio(), and Webkit + iOS happily tries to load "null" as a URL. :/
|
---|
2021 | var a = (typeof Audio !== 'undefined' ? (_isOpera ? new Audio(null) : new Audio()) : null),
|
---|
2022 | item, support = {}, aF, i;
|
---|
2023 |
|
---|
2024 | function _cp(m) {
|
---|
2025 | var canPlay, i, j, isOK = false;
|
---|
2026 | if (!a || typeof a.canPlayType !== 'function') {
|
---|
2027 | return false;
|
---|
2028 | }
|
---|
2029 | if (m instanceof Array) {
|
---|
2030 | // iterate through all mime types, return any successes
|
---|
2031 | for (i=0, j=m.length; i<j && !isOK; i++) {
|
---|
2032 | if (_s.html5[m[i]] || a.canPlayType(m[i]).match(_s.html5Test)) {
|
---|
2033 | isOK = true;
|
---|
2034 | _s.html5[m[i]] = true;
|
---|
2035 | // if flash can play and preferred, also mark it for use.
|
---|
2036 | _s.flash[m[i]] = !!(_s.preferFlash && _hasFlash && m[i].match(_flashMIME));
|
---|
2037 | }
|
---|
2038 | }
|
---|
2039 | return isOK;
|
---|
2040 | } else {
|
---|
2041 | canPlay = (a && typeof a.canPlayType === 'function' ? a.canPlayType(m) : false);
|
---|
2042 | return !!(canPlay && (canPlay.match(_s.html5Test)));
|
---|
2043 | }
|
---|
2044 | }
|
---|
2045 |
|
---|
2046 | // test all registered formats + codecs
|
---|
2047 | aF = _s.audioFormats;
|
---|
2048 | for (item in aF) {
|
---|
2049 | if (aF.hasOwnProperty(item)) {
|
---|
2050 | support[item] = _cp(aF[item].type);
|
---|
2051 | support['audio/'+item] = support[item]; // write back generic type too, eg. audio/mp3
|
---|
2052 | // assign flash
|
---|
2053 | if (_s.preferFlash && !_s.ignoreFlash && item.match(_flashMIME)) {
|
---|
2054 | _s.flash[item] = true;
|
---|
2055 | } else {
|
---|
2056 | _s.flash[item] = false;
|
---|
2057 | }
|
---|
2058 | // assign result to related formats, too
|
---|
2059 | if (aF[item] && aF[item].related) {
|
---|
2060 | for (i=aF[item].related.length; i--;) {
|
---|
2061 | support['audio/'+aF[item].related[i]] = support[item]; // eg. audio/m4a
|
---|
2062 | _s.html5[aF[item].related[i]] = support[item];
|
---|
2063 | _s.flash[aF[item].related[i]] = support[item];
|
---|
2064 | }
|
---|
2065 | }
|
---|
2066 | }
|
---|
2067 | }
|
---|
2068 |
|
---|
2069 | support.canPlayType = (a?_cp:null);
|
---|
2070 | _s.html5 = _mixin(_s.html5, support);
|
---|
2071 | return true;
|
---|
2072 |
|
---|
2073 | };
|
---|
2074 |
|
---|
2075 | _strings = {
|
---|
2076 | // <d>
|
---|
2077 | notReady: 'Not loaded yet - wait for soundManager.onload()/onready()',
|
---|
2078 | notOK: 'Audio support is not available.',
|
---|
2079 | domError: _smc + 'createMovie(): appendChild/innerHTML call failed. DOM not ready or other error.',
|
---|
2080 | spcWmode: _smc + 'createMovie(): Removing wmode, preventing known SWF loading issue(s)',
|
---|
2081 | swf404: _sm + ': Verify that %s is a valid path.',
|
---|
2082 | tryDebug: 'Try ' + _sm + '.debugFlash = true for more security details (output goes to SWF.)',
|
---|
2083 | checkSWF: 'See SWF output for more debug info.',
|
---|
2084 | 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/',
|
---|
2085 | waitFocus: _sm + ': Special case: Waiting for focus-related event..',
|
---|
2086 | waitImpatient: _sm + ': Getting impatient, still waiting for Flash%s...',
|
---|
2087 | waitForever: _sm + ': Waiting indefinitely for Flash (will recover if unblocked)...',
|
---|
2088 | needFunction: _sm + ': Function object expected for %s',
|
---|
2089 | badID: 'Warning: Sound ID "%s" should be a string, starting with a non-numeric character',
|
---|
2090 | noMS: 'MovieStar mode not enabled. Exiting.',
|
---|
2091 | currentObj: '--- ' + _sm + '._debug(): Current sound objects ---',
|
---|
2092 | waitEI: _smc + 'initMovie(): Waiting for ExternalInterface call from Flash..',
|
---|
2093 | waitOnload: _sm + ': Waiting for window.onload()',
|
---|
2094 | docLoaded: _sm + ': Document already loaded',
|
---|
2095 | onload: _smc + 'initComplete(): calling soundManager.onload()',
|
---|
2096 | onloadOK: _sm + '.onload() complete',
|
---|
2097 | init: _smc + 'init()',
|
---|
2098 | didInit: _smc + 'init(): Already called?',
|
---|
2099 | flashJS: _sm + ': Attempting to call Flash from JS..',
|
---|
2100 | noPolling: _sm + ': Polling (whileloading()/whileplaying() support) is disabled.',
|
---|
2101 | 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',
|
---|
2102 | badRemove: 'Warning: Failed to remove flash movie.',
|
---|
2103 | noPeak: 'Warning: peakData features unsupported for movieStar formats',
|
---|
2104 | shutdown: _sm + '.disable(): Shutting down',
|
---|
2105 | queue: _sm + ': Queueing %s handler',
|
---|
2106 | smFail: _sm + ': Failed to initialise.',
|
---|
2107 | smError: 'SMSound.load(): Exception: JS-Flash communication failed, or JS error.',
|
---|
2108 | fbTimeout: 'No flash response, applying .'+_s.swfCSS.swfTimedout+' CSS..',
|
---|
2109 | fbLoaded: 'Flash loaded',
|
---|
2110 | fbHandler: _smc+'flashBlockHandler()',
|
---|
2111 | manURL: 'SMSound.load(): Using manually-assigned URL',
|
---|
2112 | onURL: _sm + '.load(): current URL already assigned.',
|
---|
2113 | badFV: _sm + '.flashVersion must be 8 or 9. "%s" is invalid. Reverting to %s.',
|
---|
2114 | as2loop: 'Note: Setting stream:false so looping can work (flash 8 limitation)',
|
---|
2115 | noNSLoop: 'Note: Looping not implemented for MovieStar formats',
|
---|
2116 | needfl9: 'Note: Switching to flash 9, required for MP4 formats.',
|
---|
2117 | mfTimeout: 'Setting flashLoadTimeout = 0 (infinite) for off-screen, mobile flash case',
|
---|
2118 | mfOn: 'mobileFlash::enabling on-screen flash repositioning',
|
---|
2119 | policy: 'Enabling usePolicyFile for data access'
|
---|
2120 | // </d>
|
---|
2121 | };
|
---|
2122 |
|
---|
2123 | _str = function() { // o [,items to replace]
|
---|
2124 | // <d>
|
---|
2125 | var args = _slice.call(arguments), // real array, please
|
---|
2126 | o = args.shift(), // first arg
|
---|
2127 | str = (_strings && _strings[o]?_strings[o]:''), i, j;
|
---|
2128 | if (str && args && args.length) {
|
---|
2129 | for (i = 0, j = args.length; i < j; i++) {
|
---|
2130 | str = str.replace('%s', args[i]);
|
---|
2131 | }
|
---|
2132 | }
|
---|
2133 | return str;
|
---|
2134 | // </d>
|
---|
2135 | };
|
---|
2136 |
|
---|
2137 | _loopFix = function(sOpt) {
|
---|
2138 | // flash 8 requires stream = false for looping to work
|
---|
2139 | if (_fV === 8 && sOpt.loops > 1 && sOpt.stream) {
|
---|
2140 | _wDS('as2loop');
|
---|
2141 | sOpt.stream = false;
|
---|
2142 | }
|
---|
2143 | return sOpt;
|
---|
2144 | };
|
---|
2145 |
|
---|
2146 | _policyFix = function(sOpt, sPre) {
|
---|
2147 | if (sOpt && !sOpt.usePolicyFile && (sOpt.onid3 || sOpt.usePeakData || sOpt.useWaveformData || sOpt.useEQData)) {
|
---|
2148 | _s._wD((sPre || '') + _str('policy'));
|
---|
2149 | sOpt.usePolicyFile = true;
|
---|
2150 | }
|
---|
2151 | return sOpt;
|
---|
2152 | };
|
---|
2153 |
|
---|
2154 | _complain = function(sMsg) {
|
---|
2155 | if (typeof console !== 'undefined' && typeof console.warn !== 'undefined') {
|
---|
2156 | console.warn(sMsg);
|
---|
2157 | } else {
|
---|
2158 | _s._wD(sMsg);
|
---|
2159 | }
|
---|
2160 | };
|
---|
2161 |
|
---|
2162 | _doNothing = function() {
|
---|
2163 | return false;
|
---|
2164 | };
|
---|
2165 |
|
---|
2166 | _disableObject = function(o) {
|
---|
2167 | var oProp;
|
---|
2168 | for (oProp in o) {
|
---|
2169 | if (o.hasOwnProperty(oProp) && typeof o[oProp] === 'function') {
|
---|
2170 | o[oProp] = _doNothing;
|
---|
2171 | }
|
---|
2172 | }
|
---|
2173 | oProp = null;
|
---|
2174 | };
|
---|
2175 |
|
---|
2176 | _failSafely = function(bNoDisable) {
|
---|
2177 | // general failure exception handler
|
---|
2178 | if (typeof bNoDisable === 'undefined') {
|
---|
2179 | bNoDisable = false;
|
---|
2180 | }
|
---|
2181 | if (_disabled || bNoDisable) {
|
---|
2182 | _wDS('smFail', 2);
|
---|
2183 | _s.disable(bNoDisable);
|
---|
2184 | }
|
---|
2185 | };
|
---|
2186 |
|
---|
2187 | _normalizeMovieURL = function(smURL) {
|
---|
2188 | var urlParams = null;
|
---|
2189 | if (smURL) {
|
---|
2190 | if (smURL.match(/\.swf(\?.*)?$/i)) {
|
---|
2191 | urlParams = smURL.substr(smURL.toLowerCase().lastIndexOf('.swf?') + 4);
|
---|
2192 | if (urlParams) {
|
---|
2193 | return smURL; // assume user knows what they're doing
|
---|
2194 | }
|
---|
2195 | } else if (smURL.lastIndexOf('/') !== smURL.length - 1) {
|
---|
2196 | smURL = smURL + '/';
|
---|
2197 | }
|
---|
2198 | }
|
---|
2199 | return (smURL && smURL.lastIndexOf('/') !== - 1?smURL.substr(0, smURL.lastIndexOf('/') + 1):'./') + _s.movieURL;
|
---|
2200 | };
|
---|
2201 |
|
---|
2202 | _setVersionInfo = function() {
|
---|
2203 |
|
---|
2204 | if (_fV !== 8 && _fV !== 9) {
|
---|
2205 | _s._wD(_str('badFV', _fV, _defaultFlashVersion));
|
---|
2206 | _s.flashVersion = _defaultFlashVersion;
|
---|
2207 | }
|
---|
2208 | var isDebug = (_s.debugMode || _s.debugFlash?'_debug.swf':'.swf'); // debug flash movie, if applicable
|
---|
2209 | if (_s.useHTML5Audio && !_s.html5Only && _s.audioFormats.mp4.required && _s.flashVersion < 9) {
|
---|
2210 | _s._wD(_str('needfl9'));
|
---|
2211 | _s.flashVersion = 9;
|
---|
2212 | }
|
---|
2213 | _fV = _s.flashVersion; // short-hand for internal use
|
---|
2214 | _s.version = _s.versionNumber + (_s.html5Only?' (HTML5-only mode)':(_fV === 9?' (AS3/Flash 9)':' (AS2/Flash 8)'));
|
---|
2215 | // set up default options
|
---|
2216 | if (_fV > 8) {
|
---|
2217 | _s.defaultOptions = _mixin(_s.defaultOptions, _s.flash9Options);
|
---|
2218 | _s.features.buffering = true;
|
---|
2219 | }
|
---|
2220 | if (_fV > 8 && _s.useMovieStar) {
|
---|
2221 | // flash 9+ support for movieStar formats as well as MP3
|
---|
2222 | _s.defaultOptions = _mixin(_s.defaultOptions, _s.movieStarOptions);
|
---|
2223 | _s.filePatterns.flash9 = new RegExp('\\.(mp3|' + _s.netStreamTypes.join('|') + ')(\\?.*)?$', 'i');
|
---|
2224 | _s.mimePattern = _s.netStreamMimeTypes;
|
---|
2225 | _s.features.movieStar = true;
|
---|
2226 | } else {
|
---|
2227 | _s.useMovieStar = false;
|
---|
2228 | _s.features.movieStar = false;
|
---|
2229 | }
|
---|
2230 | _s.filePattern = _s.filePatterns[(_fV !== 8?'flash9':'flash8')];
|
---|
2231 | _s.movieURL = (_fV === 8?'soundmanager2.swf':'soundmanager2_flash9.swf').replace('.swf',isDebug);
|
---|
2232 | _s.features.peakData = _s.features.waveformData = _s.features.eqData = (_fV > 8);
|
---|
2233 | };
|
---|
2234 |
|
---|
2235 | _setPolling = function(bPolling, bHighPerformance) {
|
---|
2236 | if (!_s.o || !_s.allowPolling) {
|
---|
2237 | return false;
|
---|
2238 | }
|
---|
2239 | _s.o._setPolling(bPolling, bHighPerformance);
|
---|
2240 | };
|
---|
2241 |
|
---|
2242 | _initDebug = function() {
|
---|
2243 | if (_s.debugURLParam.test(_wl)) {
|
---|
2244 | _s.debugMode = true; // allow force of debug mode via URL
|
---|
2245 | }
|
---|
2246 | // <d>
|
---|
2247 | if (_id(_s.debugID)) {
|
---|
2248 | return false;
|
---|
2249 | }
|
---|
2250 | var oD, oDebug, oTarget, oToggle, tmp;
|
---|
2251 | if (_s.debugMode && !_id(_s.debugID) && ((!_hasConsole || !_s.useConsole) || (_s.useConsole && _hasConsole && !_s.consoleOnly))) {
|
---|
2252 | oD = _doc.createElement('div');
|
---|
2253 | oD.id = _s.debugID + '-toggle';
|
---|
2254 | oToggle = {
|
---|
2255 | 'position': 'fixed',
|
---|
2256 | 'bottom': '0px',
|
---|
2257 | 'right': '0px',
|
---|
2258 | 'width': '1.2em',
|
---|
2259 | 'height': '1.2em',
|
---|
2260 | 'lineHeight': '1.2em',
|
---|
2261 | 'margin': '2px',
|
---|
2262 | 'textAlign': 'center',
|
---|
2263 | 'border': '1px solid #999',
|
---|
2264 | 'cursor': 'pointer',
|
---|
2265 | 'background': '#fff',
|
---|
2266 | 'color': '#333',
|
---|
2267 | 'zIndex': 10001
|
---|
2268 | };
|
---|
2269 | oD.appendChild(_doc.createTextNode('-'));
|
---|
2270 | oD.onclick = _toggleDebug;
|
---|
2271 | oD.title = 'Toggle SM2 debug console';
|
---|
2272 | if (_ua.match(/msie 6/i)) {
|
---|
2273 | oD.style.position = 'absolute';
|
---|
2274 | oD.style.cursor = 'hand';
|
---|
2275 | }
|
---|
2276 | for (tmp in oToggle) {
|
---|
2277 | if (oToggle.hasOwnProperty(tmp)) {
|
---|
2278 | oD.style[tmp] = oToggle[tmp];
|
---|
2279 | }
|
---|
2280 | }
|
---|
2281 | oDebug = _doc.createElement('div');
|
---|
2282 | oDebug.id = _s.debugID;
|
---|
2283 | oDebug.style.display = (_s.debugMode?'block':'none');
|
---|
2284 | if (_s.debugMode && !_id(oD.id)) {
|
---|
2285 | try {
|
---|
2286 | oTarget = _getDocument();
|
---|
2287 | oTarget.appendChild(oD);
|
---|
2288 | } catch(e2) {
|
---|
2289 | throw new Error(_str('domError')+' \n'+e2.toString());
|
---|
2290 | }
|
---|
2291 | oTarget.appendChild(oDebug);
|
---|
2292 | }
|
---|
2293 | }
|
---|
2294 | oTarget = null;
|
---|
2295 | // </d>
|
---|
2296 | };
|
---|
2297 |
|
---|
2298 | _idCheck = this.getSoundById;
|
---|
2299 |
|
---|
2300 | // <d>
|
---|
2301 | _wDS = function(o, errorLevel) {
|
---|
2302 | if (!o) {
|
---|
2303 | return '';
|
---|
2304 | } else {
|
---|
2305 | return _s._wD(_str(o), errorLevel);
|
---|
2306 | }
|
---|
2307 | };
|
---|
2308 |
|
---|
2309 | // last-resort debugging option
|
---|
2310 | if (_wl.indexOf('sm2-debug=alert') + 1 && _s.debugMode) {
|
---|
2311 | _s._wD = function(sText) {window.alert(sText);};
|
---|
2312 | }
|
---|
2313 |
|
---|
2314 | _toggleDebug = function() {
|
---|
2315 | var o = _id(_s.debugID),
|
---|
2316 | oT = _id(_s.debugID + '-toggle');
|
---|
2317 | if (!o) {
|
---|
2318 | return false;
|
---|
2319 | }
|
---|
2320 | if (_debugOpen) {
|
---|
2321 | // minimize
|
---|
2322 | oT.innerHTML = '+';
|
---|
2323 | o.style.display = 'none';
|
---|
2324 | } else {
|
---|
2325 | oT.innerHTML = '-';
|
---|
2326 | o.style.display = 'block';
|
---|
2327 | }
|
---|
2328 | _debugOpen = !_debugOpen;
|
---|
2329 | };
|
---|
2330 |
|
---|
2331 | _debugTS = function(sEventType, bSuccess, sMessage) {
|
---|
2332 | // troubleshooter debug hooks
|
---|
2333 | if (typeof sm2Debugger !== 'undefined') {
|
---|
2334 | try {
|
---|
2335 | sm2Debugger.handleEvent(sEventType, bSuccess, sMessage);
|
---|
2336 | } catch(e) {
|
---|
2337 | // oh well
|
---|
2338 | }
|
---|
2339 | }
|
---|
2340 | return true;
|
---|
2341 | };
|
---|
2342 | // </d>
|
---|
2343 |
|
---|
2344 | _getSWFCSS = function() {
|
---|
2345 | var css = [];
|
---|
2346 | if (_s.debugMode) {
|
---|
2347 | css.push(_s.swfCSS.sm2Debug);
|
---|
2348 | }
|
---|
2349 | if (_s.debugFlash) {
|
---|
2350 | css.push(_s.swfCSS.flashDebug);
|
---|
2351 | }
|
---|
2352 | if (_s.useHighPerformance) {
|
---|
2353 | css.push(_s.swfCSS.highPerf);
|
---|
2354 | }
|
---|
2355 | return css.join(' ');
|
---|
2356 | };
|
---|
2357 |
|
---|
2358 | _flashBlockHandler = function() {
|
---|
2359 | // *possible* flash block situation.
|
---|
2360 | var name = _str('fbHandler'),
|
---|
2361 | p = _s.getMoviePercent(),
|
---|
2362 | css = _s.swfCSS,
|
---|
2363 | error = {type:'FLASHBLOCK'};
|
---|
2364 | if (_s.html5Only) {
|
---|
2365 | return false;
|
---|
2366 | }
|
---|
2367 | if (!_s.ok()) {
|
---|
2368 | if (_needsFlash) {
|
---|
2369 | // make the movie more visible, so user can fix
|
---|
2370 | _s.oMC.className = _getSWFCSS() + ' ' + css.swfDefault + ' ' + (p === null?css.swfTimedout:css.swfError);
|
---|
2371 | _s._wD(name+': '+_str('fbTimeout')+(p?' ('+_str('fbLoaded')+')':''));
|
---|
2372 | }
|
---|
2373 | _s.didFlashBlock = true;
|
---|
2374 | _processOnEvents({type:'ontimeout', ignoreInit:true, error:error}); // fire onready(), complain lightly
|
---|
2375 | _catchError(error);
|
---|
2376 | } else {
|
---|
2377 | // SM2 loaded OK (or recovered)
|
---|
2378 | if (_s.didFlashBlock) {
|
---|
2379 | _s._wD(name+': Unblocked');
|
---|
2380 | }
|
---|
2381 | if (_s.oMC) {
|
---|
2382 | _s.oMC.className = [_getSWFCSS(), css.swfDefault, css.swfLoaded + (_s.didFlashBlock?' '+css.swfUnblocked:'')].join(' ');
|
---|
2383 | }
|
---|
2384 | }
|
---|
2385 | };
|
---|
2386 |
|
---|
2387 | _addOnEvent = function(sType, oMethod, oScope) {
|
---|
2388 | if (typeof _on_queue[sType] === 'undefined') {
|
---|
2389 | _on_queue[sType] = [];
|
---|
2390 | }
|
---|
2391 | _on_queue[sType].push({
|
---|
2392 | 'method': oMethod,
|
---|
2393 | 'scope': (oScope || null),
|
---|
2394 | 'fired': false
|
---|
2395 | });
|
---|
2396 | };
|
---|
2397 |
|
---|
2398 | _processOnEvents = function(oOptions) {
|
---|
2399 | if (!oOptions) { // assume onready, if unspecified
|
---|
2400 | oOptions = {
|
---|
2401 | type: 'onready'
|
---|
2402 | };
|
---|
2403 | }
|
---|
2404 | if (!_didInit && oOptions && !oOptions.ignoreInit) {
|
---|
2405 | // not ready yet.
|
---|
2406 | return false;
|
---|
2407 | }
|
---|
2408 | if (oOptions.type === 'ontimeout' && _s.ok()) {
|
---|
2409 | // invalid case
|
---|
2410 | return false;
|
---|
2411 | }
|
---|
2412 | var status = {
|
---|
2413 | success: (oOptions && oOptions.ignoreInit?_s.ok():!_disabled)
|
---|
2414 | },
|
---|
2415 | srcQueue = (oOptions && oOptions.type?_on_queue[oOptions.type]||[]:[]), // queue specified by type, or none
|
---|
2416 | queue = [], i, j,
|
---|
2417 | args = [status],
|
---|
2418 | canRetry = (_needsFlash && _s.useFlashBlock && !_s.ok());
|
---|
2419 | if (oOptions.error) {
|
---|
2420 | args[0].error = oOptions.error;
|
---|
2421 | }
|
---|
2422 | for (i = 0, j = srcQueue.length; i < j; i++) {
|
---|
2423 | if (srcQueue[i].fired !== true) {
|
---|
2424 | queue.push(srcQueue[i]);
|
---|
2425 | }
|
---|
2426 | }
|
---|
2427 | if (queue.length) {
|
---|
2428 | _s._wD(_sm + ': Firing ' + queue.length + ' '+oOptions.type+'() item' + (queue.length === 1?'':'s'));
|
---|
2429 | for (i = 0, j = queue.length; i < j; i++) {
|
---|
2430 | if (queue[i].scope) {
|
---|
2431 | queue[i].method.apply(queue[i].scope, args);
|
---|
2432 | } else {
|
---|
2433 | queue[i].method.apply(this, args);
|
---|
2434 | }
|
---|
2435 | if (!canRetry) { // flashblock case doesn't count here
|
---|
2436 | queue[i].fired = true;
|
---|
2437 | }
|
---|
2438 | }
|
---|
2439 | }
|
---|
2440 | return true;
|
---|
2441 | };
|
---|
2442 |
|
---|
2443 | _initUserOnload = function() {
|
---|
2444 | _win.setTimeout(function() {
|
---|
2445 | if (_s.useFlashBlock) {
|
---|
2446 | _flashBlockHandler();
|
---|
2447 | }
|
---|
2448 | _processOnEvents();
|
---|
2449 | // call user-defined "onload", scoped to window
|
---|
2450 | if (_s.onload instanceof Function) {
|
---|
2451 | _wDS('onload', 1);
|
---|
2452 | _s.onload.apply(_win);
|
---|
2453 | _wDS('onloadOK', 1);
|
---|
2454 | }
|
---|
2455 | if (_s.waitForWindowLoad) {
|
---|
2456 | _event.add(_win, 'load', _initUserOnload);
|
---|
2457 | }
|
---|
2458 | },1);
|
---|
2459 | };
|
---|
2460 |
|
---|
2461 | _detectFlash = function() {
|
---|
2462 |
|
---|
2463 | // hat tip: Flash Detect library (BSD, (C) 2007) by Carl "DocYes" S. Yestrau - http://featureblend.com/javascript-flash-detection-library.html / http://featureblend.com/license.txt
|
---|
2464 |
|
---|
2465 | if (_hasFlash !== undefined) {
|
---|
2466 | // this work has already been done.
|
---|
2467 | return _hasFlash;
|
---|
2468 | }
|
---|
2469 |
|
---|
2470 | var hasPlugin = false, n = navigator, nP = n.plugins, obj, type, types, AX = _win.ActiveXObject;
|
---|
2471 |
|
---|
2472 | if (nP && nP.length) {
|
---|
2473 |
|
---|
2474 | type = 'application/x-shockwave-flash';
|
---|
2475 | types = n.mimeTypes;
|
---|
2476 | if (types && types[type] && types[type].enabledPlugin && types[type].enabledPlugin.description) {
|
---|
2477 | hasPlugin = true;
|
---|
2478 | }
|
---|
2479 |
|
---|
2480 | } else if (typeof AX !== 'undefined') {
|
---|
2481 |
|
---|
2482 | try {
|
---|
2483 | obj = new AX('ShockwaveFlash.ShockwaveFlash');
|
---|
2484 | } catch(e) {
|
---|
2485 | // oh well
|
---|
2486 | }
|
---|
2487 | hasPlugin = (!!obj);
|
---|
2488 |
|
---|
2489 | }
|
---|
2490 |
|
---|
2491 | _hasFlash = hasPlugin;
|
---|
2492 |
|
---|
2493 | return hasPlugin;
|
---|
2494 |
|
---|
2495 | };
|
---|
2496 |
|
---|
2497 | _featureCheck = function() {
|
---|
2498 |
|
---|
2499 | var needsFlash, item,
|
---|
2500 | 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.
|
---|
2501 |
|
---|
2502 | if (isSpecial) {
|
---|
2503 | _s.hasHTML5 = false; // has Audio(), but is broken; let it load links directly.
|
---|
2504 | _s.html5Only = true; // ignore flash case, however
|
---|
2505 | if (_s.oMC) {
|
---|
2506 | _s.oMC.style.display = 'none';
|
---|
2507 | }
|
---|
2508 | return false;
|
---|
2509 | }
|
---|
2510 |
|
---|
2511 | if (_s.useHTML5Audio) {
|
---|
2512 | if (!_s.html5 || !_s.html5.canPlayType) {
|
---|
2513 | _s._wD('SoundManager: No HTML5 Audio() support detected.');
|
---|
2514 | _s.hasHTML5 = false;
|
---|
2515 | return true;
|
---|
2516 | } else {
|
---|
2517 | _s.hasHTML5 = true;
|
---|
2518 | }
|
---|
2519 | if (_isBadSafari) {
|
---|
2520 | _s._wD(_smc+'Note: Buggy HTML5 Audio in Safari on this OS X release, see https://bugs.webkit.org/show_bug.cgi?id=32159 - '+(!_hasFlash?' would use flash fallback for MP3/MP4, but none detected.':'will use flash fallback for MP3/MP4, if available'),1);
|
---|
2521 | if (_detectFlash()) {
|
---|
2522 | return true;
|
---|
2523 | }
|
---|
2524 | }
|
---|
2525 | } else {
|
---|
2526 | // flash needed (or, HTML5 needs enabling.)
|
---|
2527 | return true;
|
---|
2528 | }
|
---|
2529 |
|
---|
2530 | for (item in _s.audioFormats) {
|
---|
2531 | if (_s.audioFormats.hasOwnProperty(item)) {
|
---|
2532 | if ( (_s.audioFormats[item].required && !_s.html5.canPlayType(_s.audioFormats[item].type)) || _s.flash[item] || _s.flash[_s.audioFormats[item].type]) {
|
---|
2533 | // flash may be required, or preferred for this format
|
---|
2534 | needsFlash = true;
|
---|
2535 | }
|
---|
2536 | }
|
---|
2537 | }
|
---|
2538 |
|
---|
2539 | // sanity check..
|
---|
2540 | if (_s.ignoreFlash) {
|
---|
2541 | needsFlash = false;
|
---|
2542 | }
|
---|
2543 |
|
---|
2544 | _s.html5Only = (_s.hasHTML5 && _s.useHTML5Audio && !needsFlash);
|
---|
2545 |
|
---|
2546 | return (!_s.html5Only);
|
---|
2547 |
|
---|
2548 | };
|
---|
2549 |
|
---|
2550 | _startTimer = function(oSound) {
|
---|
2551 | if (!oSound._hasTimer) {
|
---|
2552 | oSound._hasTimer = true;
|
---|
2553 | }
|
---|
2554 | };
|
---|
2555 |
|
---|
2556 | _stopTimer = function(oSound) {
|
---|
2557 | if (oSound._hasTimer) {
|
---|
2558 | oSound._hasTimer = false;
|
---|
2559 | }
|
---|
2560 | };
|
---|
2561 |
|
---|
2562 | _catchError = function(options) {
|
---|
2563 | options = (typeof options !== 'undefined' ? options : {});
|
---|
2564 | if (_s.onerror instanceof Function) {
|
---|
2565 | _s.onerror.apply(_win, [{type:(typeof options.type !== 'undefined' ? options.type : null)}]);
|
---|
2566 | }
|
---|
2567 | if (typeof options.fatal !== 'undefined' && options.fatal) {
|
---|
2568 | _s.disable();
|
---|
2569 | }
|
---|
2570 | };
|
---|
2571 |
|
---|
2572 | _badSafariFix = function() {
|
---|
2573 | // special case: "bad" Safari (OS X 10.3 - 10.7) must fall back to flash for MP3/MP4
|
---|
2574 | if (!_isBadSafari || !_detectFlash()) {
|
---|
2575 | return false; // doesn't apply
|
---|
2576 | }
|
---|
2577 | var aF = _s.audioFormats, i, item;
|
---|
2578 | for (item in aF) {
|
---|
2579 | if (aF.hasOwnProperty(item)) {
|
---|
2580 | if (item === 'mp3' || item === 'mp4') {
|
---|
2581 | _s._wD(_sm+': Using flash fallback for '+item+' format');
|
---|
2582 | _s.html5[item] = false;
|
---|
2583 | // assign result to related formats, too
|
---|
2584 | if (aF[item] && aF[item].related) {
|
---|
2585 | for (i = aF[item].related.length; i--;) {
|
---|
2586 | _s.html5[aF[item].related[i]] = false;
|
---|
2587 | }
|
---|
2588 | }
|
---|
2589 | }
|
---|
2590 | }
|
---|
2591 | }
|
---|
2592 | };
|
---|
2593 |
|
---|
2594 | /*
|
---|
2595 | * pseudo-private flash/ExternalInterface methods
|
---|
2596 | */
|
---|
2597 |
|
---|
2598 | this._setSandboxType = function(sandboxType) {
|
---|
2599 | // <d>
|
---|
2600 | var sb = _s.sandbox;
|
---|
2601 | sb.type = sandboxType;
|
---|
2602 | sb.description = sb.types[(typeof sb.types[sandboxType] !== 'undefined'?sandboxType:'unknown')];
|
---|
2603 | _s._wD('Flash security sandbox type: ' + sb.type);
|
---|
2604 | if (sb.type === 'localWithFile') {
|
---|
2605 | sb.noRemote = true;
|
---|
2606 | sb.noLocal = false;
|
---|
2607 | _wDS('secNote', 2);
|
---|
2608 | } else if (sb.type === 'localWithNetwork') {
|
---|
2609 | sb.noRemote = false;
|
---|
2610 | sb.noLocal = true;
|
---|
2611 | } else if (sb.type === 'localTrusted') {
|
---|
2612 | sb.noRemote = false;
|
---|
2613 | sb.noLocal = false;
|
---|
2614 | }
|
---|
2615 | // </d>
|
---|
2616 | };
|
---|
2617 |
|
---|
2618 | this._externalInterfaceOK = function(flashDate) {
|
---|
2619 | // flash callback confirming flash loaded, EI working etc.
|
---|
2620 | // flashDate = approx. timing/delay info for JS/flash bridge
|
---|
2621 | if (_s.swfLoaded) {
|
---|
2622 | return false;
|
---|
2623 | }
|
---|
2624 | var eiTime = new Date().getTime();
|
---|
2625 | _s._wD(_smc+'externalInterfaceOK()' + (flashDate?' (~' + (eiTime - flashDate) + ' ms)':''));
|
---|
2626 | _debugTS('swf', true);
|
---|
2627 | _debugTS('flashtojs', true);
|
---|
2628 | _s.swfLoaded = true;
|
---|
2629 | _tryInitOnFocus = false;
|
---|
2630 | if (_isBadSafari) {
|
---|
2631 | _badSafariFix();
|
---|
2632 | }
|
---|
2633 | if (_isIE) {
|
---|
2634 | // IE needs a timeout OR delay until window.onload - may need TODO: investigating
|
---|
2635 | setTimeout(_init, 100);
|
---|
2636 | } else {
|
---|
2637 | _init();
|
---|
2638 | }
|
---|
2639 | };
|
---|
2640 |
|
---|
2641 | /*
|
---|
2642 | * private initialization helpers
|
---|
2643 | */
|
---|
2644 |
|
---|
2645 | _createMovie = function(smID, smURL) {
|
---|
2646 |
|
---|
2647 | if (_didAppend && _appendSuccess) {
|
---|
2648 | return false; // ignore if already succeeded
|
---|
2649 | }
|
---|
2650 |
|
---|
2651 | function _initMsg() {
|
---|
2652 | _s._wD('-- SoundManager 2 ' + _s.version + (!_s.html5Only && _s.useHTML5Audio?(_s.hasHTML5?' + HTML5 audio':', no HTML5 audio support'):'') + (!_s.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);
|
---|
2653 | }
|
---|
2654 |
|
---|
2655 | if (_s.html5Only) {
|
---|
2656 | // 100% HTML5 mode
|
---|
2657 | _setVersionInfo();
|
---|
2658 | _initMsg();
|
---|
2659 | _s.oMC = _id(_s.movieID);
|
---|
2660 | _init();
|
---|
2661 | // prevent multiple init attempts
|
---|
2662 | _didAppend = true;
|
---|
2663 | _appendSuccess = true;
|
---|
2664 | return false;
|
---|
2665 | }
|
---|
2666 |
|
---|
2667 | // flash path
|
---|
2668 | var remoteURL = (smURL || _s.url),
|
---|
2669 | localURL = (_s.altURL || remoteURL),
|
---|
2670 | swfTitle = 'JS/Flash audio component (SoundManager 2)',
|
---|
2671 | oEmbed, oMovie, oTarget = _getDocument(), tmp, movieHTML, oEl, extraClass = _getSWFCSS(), s, x, sClass, side = 'auto', isRTL = null, html = _doc.getElementsByTagName('html')[0];
|
---|
2672 |
|
---|
2673 | isRTL = (html && html.dir && html.dir.match(/rtl/i));
|
---|
2674 | smID = (typeof smID === 'undefined'?_s.id:smID);
|
---|
2675 |
|
---|
2676 | function param(name, value) {
|
---|
2677 | return '<param name="'+name+'" value="'+value+'" />';
|
---|
2678 | }
|
---|
2679 |
|
---|
2680 | // safety check for legacy (change to Flash 9 URL)
|
---|
2681 | _setVersionInfo();
|
---|
2682 | _s.url = _normalizeMovieURL(_overHTTP?remoteURL:localURL);
|
---|
2683 | smURL = _s.url;
|
---|
2684 |
|
---|
2685 | _s.wmode = (!_s.wmode && _s.useHighPerformance && !_s.useMovieStar?'transparent':_s.wmode);
|
---|
2686 |
|
---|
2687 | if (_s.wmode !== null && (_ua.match(/msie 8/i) || (!_isIE && !_s.useHighPerformance)) && navigator.platform.match(/win32|win64/i)) {
|
---|
2688 | /*
|
---|
2689 | * extra-special case: movie doesn't load until scrolled into view when using wmode = anything but 'window' here
|
---|
2690 | * does not apply when using high performance (position:fixed means on-screen), OR infinite flash load timeout
|
---|
2691 | * wmode breaks IE 8 on Vista + Win7 too in some cases, as of January 2011 (?)
|
---|
2692 | */
|
---|
2693 | _s.specialWmodeCase = true;
|
---|
2694 | _wDS('spcWmode');
|
---|
2695 | _s.wmode = null;
|
---|
2696 | }
|
---|
2697 |
|
---|
2698 | oEmbed = {
|
---|
2699 | 'name': smID,
|
---|
2700 | 'id': smID,
|
---|
2701 | 'src': smURL,
|
---|
2702 | 'width': side,
|
---|
2703 | 'height': side,
|
---|
2704 | 'quality': 'high',
|
---|
2705 | 'allowScriptAccess': _s.allowScriptAccess,
|
---|
2706 | 'bgcolor': _s.bgColor,
|
---|
2707 | 'pluginspage': _http+'//www.macromedia.com/go/getflashplayer',
|
---|
2708 | 'title': swfTitle,
|
---|
2709 | 'type': 'application/x-shockwave-flash',
|
---|
2710 | 'wmode': _s.wmode,
|
---|
2711 | 'hasPriority': 'true' // http://help.adobe.com/en_US/as3/mobile/WS4bebcd66a74275c36cfb8137124318eebc6-7ffd.html
|
---|
2712 | };
|
---|
2713 |
|
---|
2714 | if (_s.debugFlash) {
|
---|
2715 | oEmbed.FlashVars = 'debug=1';
|
---|
2716 | }
|
---|
2717 |
|
---|
2718 | if (!_s.wmode) {
|
---|
2719 | delete oEmbed.wmode; // don't write empty attribute
|
---|
2720 | }
|
---|
2721 |
|
---|
2722 | if (_isIE) {
|
---|
2723 |
|
---|
2724 | // IE is "special".
|
---|
2725 | oMovie = _doc.createElement('div');
|
---|
2726 | movieHTML = [
|
---|
2727 | '<object id="' + smID + '" data="' + smURL + '" type="' + oEmbed.type + '" title="' + oEmbed.title +'" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="' + _http+'//download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" width="' + oEmbed.width + '" height="' + oEmbed.height + '">',
|
---|
2728 | param('movie', smURL),
|
---|
2729 | param('AllowScriptAccess', _s.allowScriptAccess),
|
---|
2730 | param('quality', oEmbed.quality),
|
---|
2731 | (_s.wmode? param('wmode', _s.wmode): ''),
|
---|
2732 | param('bgcolor', _s.bgColor),
|
---|
2733 | param('hasPriority', 'true'),
|
---|
2734 | (_s.debugFlash ? param('FlashVars', oEmbed.FlashVars) : ''),
|
---|
2735 | '</object>'
|
---|
2736 | ].join('');
|
---|
2737 |
|
---|
2738 | } else {
|
---|
2739 |
|
---|
2740 | oMovie = _doc.createElement('embed');
|
---|
2741 | for (tmp in oEmbed) {
|
---|
2742 | if (oEmbed.hasOwnProperty(tmp)) {
|
---|
2743 | oMovie.setAttribute(tmp, oEmbed[tmp]);
|
---|
2744 | }
|
---|
2745 | }
|
---|
2746 |
|
---|
2747 | }
|
---|
2748 |
|
---|
2749 | _initDebug();
|
---|
2750 | extraClass = _getSWFCSS();
|
---|
2751 | oTarget = _getDocument();
|
---|
2752 |
|
---|
2753 | if (oTarget) {
|
---|
2754 |
|
---|
2755 | _s.oMC = (_id(_s.movieID) || _doc.createElement('div'));
|
---|
2756 |
|
---|
2757 | if (!_s.oMC.id) {
|
---|
2758 |
|
---|
2759 | _s.oMC.id = _s.movieID;
|
---|
2760 | _s.oMC.className = _s.swfCSS.swfDefault + ' ' + extraClass;
|
---|
2761 | s = null;
|
---|
2762 | oEl = null;
|
---|
2763 |
|
---|
2764 | if (!_s.useFlashBlock) {
|
---|
2765 | if (_s.useHighPerformance) {
|
---|
2766 | // on-screen at all times
|
---|
2767 | s = {
|
---|
2768 | 'position': 'fixed',
|
---|
2769 | 'width': '8px',
|
---|
2770 | 'height': '8px',
|
---|
2771 | // >= 6px for flash to run fast, >= 8px to start up under Firefox/win32 in some cases. odd? yes.
|
---|
2772 | 'bottom': '0px',
|
---|
2773 | 'left': '0px',
|
---|
2774 | 'overflow': 'hidden'
|
---|
2775 | };
|
---|
2776 | } else {
|
---|
2777 | // hide off-screen, lower priority
|
---|
2778 | s = {
|
---|
2779 | 'position': 'absolute',
|
---|
2780 | 'width': '6px',
|
---|
2781 | 'height': '6px',
|
---|
2782 | 'top': '-9999px',
|
---|
2783 | 'left': '-9999px'
|
---|
2784 | };
|
---|
2785 | if (isRTL) {
|
---|
2786 | s.left = Math.abs(parseInt(s.left,10))+'px';
|
---|
2787 | }
|
---|
2788 | }
|
---|
2789 | }
|
---|
2790 |
|
---|
2791 | if (_isWebkit) {
|
---|
2792 | _s.oMC.style.zIndex = 10000; // soundcloud-reported render/crash fix, safari 5
|
---|
2793 | }
|
---|
2794 |
|
---|
2795 | if (!_s.debugFlash) {
|
---|
2796 | for (x in s) {
|
---|
2797 | if (s.hasOwnProperty(x)) {
|
---|
2798 | _s.oMC.style[x] = s[x];
|
---|
2799 | }
|
---|
2800 | }
|
---|
2801 | }
|
---|
2802 |
|
---|
2803 | try {
|
---|
2804 | if (!_isIE) {
|
---|
2805 | _s.oMC.appendChild(oMovie);
|
---|
2806 | }
|
---|
2807 | oTarget.appendChild(_s.oMC);
|
---|
2808 | if (_isIE) {
|
---|
2809 | oEl = _s.oMC.appendChild(_doc.createElement('div'));
|
---|
2810 | oEl.className = _s.swfCSS.swfBox;
|
---|
2811 | oEl.innerHTML = movieHTML;
|
---|
2812 | }
|
---|
2813 | _appendSuccess = true;
|
---|
2814 | } catch(e) {
|
---|
2815 | throw new Error(_str('domError')+' \n'+e.toString());
|
---|
2816 | }
|
---|
2817 |
|
---|
2818 | } else {
|
---|
2819 |
|
---|
2820 | // SM2 container is already in the document (eg. flashblock use case)
|
---|
2821 | sClass = _s.oMC.className;
|
---|
2822 | _s.oMC.className = (sClass?sClass+' ':_s.swfCSS.swfDefault) + (extraClass?' '+extraClass:'');
|
---|
2823 | _s.oMC.appendChild(oMovie);
|
---|
2824 | if (_isIE) {
|
---|
2825 | oEl = _s.oMC.appendChild(_doc.createElement('div'));
|
---|
2826 | oEl.className = _s.swfCSS.swfBox;
|
---|
2827 | oEl.innerHTML = movieHTML;
|
---|
2828 | }
|
---|
2829 | _appendSuccess = true;
|
---|
2830 |
|
---|
2831 | }
|
---|
2832 |
|
---|
2833 | }
|
---|
2834 |
|
---|
2835 | _didAppend = true;
|
---|
2836 | _initMsg();
|
---|
2837 | _s._wD(_smc+'createMovie(): Trying to load ' + smURL + (!_overHTTP && _s.altURL?' (alternate URL)':''), 1);
|
---|
2838 |
|
---|
2839 | return true;
|
---|
2840 |
|
---|
2841 | };
|
---|
2842 |
|
---|
2843 | _initMovie = function() {
|
---|
2844 |
|
---|
2845 | if (_s.html5Only) {
|
---|
2846 | _createMovie();
|
---|
2847 | return false;
|
---|
2848 | }
|
---|
2849 |
|
---|
2850 | // attempt to get, or create, movie
|
---|
2851 | if (_s.o) {
|
---|
2852 | return false; // may already exist
|
---|
2853 | }
|
---|
2854 |
|
---|
2855 | _s.o = _s.getMovie(_s.id); // inline markup
|
---|
2856 |
|
---|
2857 | if (!_s.o) {
|
---|
2858 | if (!_oRemoved) {
|
---|
2859 | // try to create
|
---|
2860 | _createMovie(_s.id, _s.url);
|
---|
2861 | } else {
|
---|
2862 | // try to re-append removed movie after reboot()
|
---|
2863 | if (!_isIE) {
|
---|
2864 | _s.oMC.appendChild(_oRemoved);
|
---|
2865 | } else {
|
---|
2866 | _s.oMC.innerHTML = _oRemovedHTML;
|
---|
2867 | }
|
---|
2868 | _oRemoved = null;
|
---|
2869 | _didAppend = true;
|
---|
2870 | }
|
---|
2871 | _s.o = _s.getMovie(_s.id);
|
---|
2872 | }
|
---|
2873 |
|
---|
2874 | if (_s.o) {
|
---|
2875 | _wDS('waitEI');
|
---|
2876 | }
|
---|
2877 |
|
---|
2878 | if (_s.oninitmovie instanceof Function) {
|
---|
2879 | setTimeout(_s.oninitmovie, 1);
|
---|
2880 | }
|
---|
2881 |
|
---|
2882 | return true;
|
---|
2883 |
|
---|
2884 | };
|
---|
2885 |
|
---|
2886 | _delayWaitForEI = function() {
|
---|
2887 | setTimeout(_waitForEI, 1000);
|
---|
2888 | };
|
---|
2889 |
|
---|
2890 | _waitForEI = function() {
|
---|
2891 |
|
---|
2892 | if (_waitingForEI) {
|
---|
2893 | return false;
|
---|
2894 | }
|
---|
2895 |
|
---|
2896 | _waitingForEI = true;
|
---|
2897 | _event.remove(_win, 'load', _delayWaitForEI);
|
---|
2898 |
|
---|
2899 | if (_tryInitOnFocus && !_isFocused) {
|
---|
2900 | // giant Safari 3.1 hack - assume mousemove = focus given lack of focus event
|
---|
2901 | _wDS('waitFocus');
|
---|
2902 | return false;
|
---|
2903 | }
|
---|
2904 |
|
---|
2905 | var p;
|
---|
2906 | if (!_didInit) {
|
---|
2907 | p = _s.getMoviePercent();
|
---|
2908 | _s._wD(_str('waitImpatient', (p === 100?' (SWF loaded)':(p > 0?' (SWF ' + p + '% loaded)':''))));
|
---|
2909 | }
|
---|
2910 |
|
---|
2911 | setTimeout(function() {
|
---|
2912 |
|
---|
2913 | p = _s.getMoviePercent();
|
---|
2914 |
|
---|
2915 | if (!_didInit) {
|
---|
2916 | _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);
|
---|
2917 | if (!_overHTTP && p) {
|
---|
2918 | _wDS('localFail', 2);
|
---|
2919 | if (!_s.debugFlash) {
|
---|
2920 | _wDS('tryDebug', 2);
|
---|
2921 | }
|
---|
2922 | }
|
---|
2923 | if (p === 0) {
|
---|
2924 | // if 0 (not null), probably a 404.
|
---|
2925 | _s._wD(_str('swf404', _s.url));
|
---|
2926 | }
|
---|
2927 | _debugTS('flashtojs', false, ': Timed out' + _overHTTP?' (Check flash security or flash blockers)':' (No plugin/missing SWF?)');
|
---|
2928 | }
|
---|
2929 |
|
---|
2930 | // give up / time-out, depending
|
---|
2931 | if (!_didInit && _okToDisable) {
|
---|
2932 | if (p === null) {
|
---|
2933 | // SWF failed. Maybe blocked.
|
---|
2934 | if (_s.useFlashBlock || _s.flashLoadTimeout === 0) {
|
---|
2935 | if (_s.useFlashBlock) {
|
---|
2936 | _flashBlockHandler();
|
---|
2937 | }
|
---|
2938 | _wDS('waitForever');
|
---|
2939 | } else {
|
---|
2940 | // old SM2 behaviour, simply fail
|
---|
2941 | _failSafely(true);
|
---|
2942 | }
|
---|
2943 |
|
---|
2944 | } else {
|
---|
2945 | // flash loaded? Shouldn't be a blocking issue, then.
|
---|
2946 | if (_s.flashLoadTimeout === 0) {
|
---|
2947 | _wDS('waitForever');
|
---|
2948 | } else {
|
---|
2949 | _failSafely(true);
|
---|
2950 | }
|
---|
2951 | }
|
---|
2952 | }
|
---|
2953 |
|
---|
2954 | }, _s.flashLoadTimeout);
|
---|
2955 |
|
---|
2956 | };
|
---|
2957 |
|
---|
2958 | _handleFocus = function() {
|
---|
2959 | function cleanup() {
|
---|
2960 | _event.remove(_win, 'focus', _handleFocus);
|
---|
2961 | _event.remove(_win, 'load', _handleFocus);
|
---|
2962 | }
|
---|
2963 | if (_isFocused || !_tryInitOnFocus) {
|
---|
2964 | cleanup();
|
---|
2965 | return true;
|
---|
2966 | }
|
---|
2967 | _okToDisable = true;
|
---|
2968 | _isFocused = true;
|
---|
2969 | _s._wD(_smc+'handleFocus()');
|
---|
2970 | if (_isSafari && _tryInitOnFocus) {
|
---|
2971 | _event.remove(_win, 'mousemove', _handleFocus);
|
---|
2972 | }
|
---|
2973 | // allow init to restart
|
---|
2974 | _waitingForEI = false;
|
---|
2975 | cleanup();
|
---|
2976 | return true;
|
---|
2977 | };
|
---|
2978 |
|
---|
2979 | _initComplete = function(bNoDisable) {
|
---|
2980 | if (_didInit) {
|
---|
2981 | return false;
|
---|
2982 | }
|
---|
2983 | if (_s.html5Only) {
|
---|
2984 | // all good.
|
---|
2985 | _s._wD('-- SoundManager 2: loaded --');
|
---|
2986 | _didInit = true;
|
---|
2987 | _initUserOnload();
|
---|
2988 | _debugTS('onload', true);
|
---|
2989 | return true;
|
---|
2990 | }
|
---|
2991 | var wasTimeout = (_s.useFlashBlock && _s.flashLoadTimeout && !_s.getMoviePercent()),
|
---|
2992 | error;
|
---|
2993 | if (!wasTimeout) {
|
---|
2994 | _didInit = true;
|
---|
2995 | if (_disabled) {
|
---|
2996 | error = {type: (!_hasFlash && _needsFlash ? 'NO_FLASH' : 'INIT_TIMEOUT')};
|
---|
2997 | }
|
---|
2998 | }
|
---|
2999 | _s._wD('-- SoundManager 2 ' + (_disabled?'failed to load':'loaded') + ' (' + (_disabled?'security/load error':'OK') + ') --', 1);
|
---|
3000 | if (_disabled || bNoDisable) {
|
---|
3001 | if (_s.useFlashBlock && _s.oMC) {
|
---|
3002 | _s.oMC.className = _getSWFCSS() + ' ' + (_s.getMoviePercent() === null?_s.swfCSS.swfTimedout:_s.swfCSS.swfError);
|
---|
3003 | }
|
---|
3004 | _processOnEvents({type:'ontimeout', error:error});
|
---|
3005 | _debugTS('onload', false);
|
---|
3006 | _catchError(error);
|
---|
3007 | return false;
|
---|
3008 | } else {
|
---|
3009 | _debugTS('onload', true);
|
---|
3010 | }
|
---|
3011 | _event.add(_win, 'unload', _doNothing); // prevent browser from showing cached state via back button, because flash will be dead
|
---|
3012 | if (_s.waitForWindowLoad && !_windowLoaded) {
|
---|
3013 | _wDS('waitOnload');
|
---|
3014 | _event.add(_win, 'load', _initUserOnload);
|
---|
3015 | return false;
|
---|
3016 | } else {
|
---|
3017 | if (_s.waitForWindowLoad && _windowLoaded) {
|
---|
3018 | _wDS('docLoaded');
|
---|
3019 | }
|
---|
3020 | _initUserOnload();
|
---|
3021 | }
|
---|
3022 | return true;
|
---|
3023 | };
|
---|
3024 |
|
---|
3025 | _showSupport = function() {
|
---|
3026 |
|
---|
3027 | var item, tests = [];
|
---|
3028 | if (_s.useHTML5Audio && _s.hasHTML5) {
|
---|
3029 | for (item in _s.audioFormats) {
|
---|
3030 | if (_s.audioFormats.hasOwnProperty(item)) {
|
---|
3031 | tests.push(item + ': ' + _s.html5[item] + (!_s.html5[item] && _hasFlash && _s.flash[item] ? ' (using flash)' : (_s.preferFlash && _s.flash[item] && _hasFlash ? ' (preferring flash)': (!_s.html5[item] ? ' (' + (_s.audioFormats[item].required ? 'required, ':'') + 'and no flash support)' : ''))));
|
---|
3032 | }
|
---|
3033 | }
|
---|
3034 | _s._wD('-- SoundManager 2: HTML5 support tests ('+_s.html5Test+'): '+tests.join(', ')+' --',1);
|
---|
3035 | }
|
---|
3036 |
|
---|
3037 | };
|
---|
3038 |
|
---|
3039 | _init = function() {
|
---|
3040 |
|
---|
3041 | _wDS('init');
|
---|
3042 |
|
---|
3043 | // called after onload()
|
---|
3044 | if (_didInit) {
|
---|
3045 | _wDS('didInit');
|
---|
3046 | return false;
|
---|
3047 | }
|
---|
3048 |
|
---|
3049 | function _cleanup() {
|
---|
3050 | _event.remove(_win, 'load', _s.beginDelayedInit);
|
---|
3051 | }
|
---|
3052 |
|
---|
3053 | if (_s.html5Only) {
|
---|
3054 | if (!_didInit) {
|
---|
3055 | // we don't need no steenking flash!
|
---|
3056 | _cleanup();
|
---|
3057 | _s.enabled = true;
|
---|
3058 | _initComplete();
|
---|
3059 | }
|
---|
3060 | return true;
|
---|
3061 | }
|
---|
3062 |
|
---|
3063 | // flash path
|
---|
3064 | _initMovie();
|
---|
3065 |
|
---|
3066 | try {
|
---|
3067 | _wDS('flashJS');
|
---|
3068 | _s.o._externalInterfaceTest(false); // attempt to talk to Flash
|
---|
3069 | if (!_s.allowPolling) {
|
---|
3070 | _wDS('noPolling', 1);
|
---|
3071 | } else {
|
---|
3072 | _setPolling(true, (_s.flashPollingInterval || (_s.useFastPolling ? 10 : 50)));
|
---|
3073 | }
|
---|
3074 | if (!_s.debugMode) {
|
---|
3075 | _s.o._disableDebug();
|
---|
3076 | }
|
---|
3077 | _s.enabled = true;
|
---|
3078 | _debugTS('jstoflash', true);
|
---|
3079 | } catch(e) {
|
---|
3080 | _s._wD('js/flash exception: ' + e.toString());
|
---|
3081 | _debugTS('jstoflash', false);
|
---|
3082 | _catchError({type:'JS_TO_FLASH_EXCEPTION', fatal:true});
|
---|
3083 | _failSafely(true); // don't disable, for reboot()
|
---|
3084 | _initComplete();
|
---|
3085 | return false;
|
---|
3086 | }
|
---|
3087 |
|
---|
3088 | _initComplete();
|
---|
3089 | // event cleanup
|
---|
3090 | _cleanup();
|
---|
3091 | return true;
|
---|
3092 |
|
---|
3093 | };
|
---|
3094 |
|
---|
3095 | _dcLoaded = function() {
|
---|
3096 | if (_didDCLoaded) {
|
---|
3097 | return false;
|
---|
3098 | }
|
---|
3099 | _didDCLoaded = true;
|
---|
3100 | _initDebug();
|
---|
3101 |
|
---|
3102 | /*
|
---|
3103 | * Temporary feature: allow force of HTML5 via URL params: sm2-usehtml5audio=0 or 1
|
---|
3104 | * Ditto for sm2-preferFlash, too.
|
---|
3105 | */
|
---|
3106 | // <d>
|
---|
3107 | (function(){
|
---|
3108 | var a = 'sm2-usehtml5audio=', l = _wl.toLowerCase(), b = null,
|
---|
3109 | a2 = 'sm2-preferflash=', b2 = null, hasCon = (typeof console !== 'undefined' && typeof console.log !== 'undefined');
|
---|
3110 | if (l.indexOf(a) !== -1) {
|
---|
3111 | b = (l.charAt(l.indexOf(a)+a.length) === '1');
|
---|
3112 | if (hasCon) {
|
---|
3113 | console.log((b?'Enabling ':'Disabling ')+'useHTML5Audio via URL parameter');
|
---|
3114 | }
|
---|
3115 | _s.useHTML5Audio = b;
|
---|
3116 | }
|
---|
3117 | if (l.indexOf(a2) !== -1) {
|
---|
3118 | b2 = (l.charAt(l.indexOf(a2)+a2.length) === '1');
|
---|
3119 | if (hasCon) {
|
---|
3120 | console.log((b2?'Enabling ':'Disabling ')+'preferFlash via URL parameter');
|
---|
3121 | }
|
---|
3122 | _s.preferFlash = b2;
|
---|
3123 | }
|
---|
3124 | }());
|
---|
3125 | // </d>
|
---|
3126 |
|
---|
3127 | if (!_hasFlash && _s.hasHTML5) {
|
---|
3128 | _s._wD('SoundManager: No Flash detected'+(!_s.useHTML5Audio?', enabling HTML5.':'. Trying HTML5-only mode.'));
|
---|
3129 | _s.useHTML5Audio = true;
|
---|
3130 | // make sure we aren't preferring flash, either
|
---|
3131 | // TODO: preferFlash should not matter if flash is not installed. Currently, stuff breaks without the below tweak.
|
---|
3132 | _s.preferFlash = false;
|
---|
3133 | }
|
---|
3134 |
|
---|
3135 | _testHTML5();
|
---|
3136 | _s.html5.usingFlash = _featureCheck();
|
---|
3137 | _needsFlash = _s.html5.usingFlash;
|
---|
3138 |
|
---|
3139 | _showSupport();
|
---|
3140 |
|
---|
3141 | if (!_hasFlash && _needsFlash) {
|
---|
3142 | _s._wD('SoundManager: Fatal error: Flash is needed to play some required formats, but is not available.');
|
---|
3143 | // TODO: Fatal here vs. timeout approach, etc.
|
---|
3144 | _s.flashLoadTimeout = 1; // hack: fail sooner.
|
---|
3145 | }
|
---|
3146 |
|
---|
3147 | if (_doc.removeEventListener) {
|
---|
3148 | _doc.removeEventListener('DOMContentLoaded', _dcLoaded, false);
|
---|
3149 | }
|
---|
3150 | _initMovie();
|
---|
3151 | return true;
|
---|
3152 | };
|
---|
3153 |
|
---|
3154 | _dcIE = function() {
|
---|
3155 | if (_doc.readyState === 'complete') {
|
---|
3156 | _dcLoaded();
|
---|
3157 | _doc.detachEvent('onreadystatechange', _dcIE);
|
---|
3158 | }
|
---|
3159 | return true;
|
---|
3160 | };
|
---|
3161 |
|
---|
3162 | // sniff up-front
|
---|
3163 | _detectFlash();
|
---|
3164 |
|
---|
3165 | // focus and window load, init (primarily flash-driven)
|
---|
3166 | _event.add(_win, 'focus', _handleFocus);
|
---|
3167 | _event.add(_win, 'load', _handleFocus);
|
---|
3168 | _event.add(_win, 'load', _delayWaitForEI);
|
---|
3169 | if (_isSafari && _tryInitOnFocus) {
|
---|
3170 | _event.add(_win, 'mousemove', _handleFocus); // massive Safari 3.1 focus hack
|
---|
3171 | }
|
---|
3172 |
|
---|
3173 | if (_doc.addEventListener) {
|
---|
3174 | _doc.addEventListener('DOMContentLoaded', _dcLoaded, false);
|
---|
3175 | } else if (_doc.attachEvent) {
|
---|
3176 | _doc.attachEvent('onreadystatechange', _dcIE);
|
---|
3177 | } else {
|
---|
3178 | // no add/attachevent support - safe to assume no JS -> Flash either
|
---|
3179 | _debugTS('onload', false);
|
---|
3180 | _catchError({type:'NO_DOM2_EVENTS', fatal:true});
|
---|
3181 | }
|
---|
3182 |
|
---|
3183 | if (_doc.readyState === 'complete') {
|
---|
3184 | setTimeout(_dcLoaded,100);
|
---|
3185 | }
|
---|
3186 |
|
---|
3187 | } // SoundManager()
|
---|
3188 |
|
---|
3189 | // SM2_DEFER details: http://www.schillmania.com/projects/soundmanager2/doc/getstarted/#lazy-loading
|
---|
3190 | if (typeof SM2_DEFER === 'undefined' || !SM2_DEFER) {
|
---|
3191 | soundManager = new SoundManager();
|
---|
3192 | }
|
---|
3193 |
|
---|
3194 | // public interfaces
|
---|
3195 | window.SoundManager = SoundManager; // constructor
|
---|
3196 | window.soundManager = soundManager; // public API, flash callbacks etc
|
---|
3197 |
|
---|
3198 | }(window)); |
---|