soundmanager-rails 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -8,7 +8,7 @@
8
8
  * Code provided under the BSD License:
9
9
  * http://schillmania.com/projects/soundmanager2/license.txt
10
10
  *
11
- * V2.97a.20120624
11
+ * V2.97a.20120916
12
12
  */
13
13
 
14
14
  /*global window, SM2_DEFER, sm2Debugger, console, document, navigator, setTimeout, setInterval, clearInterval, Audio */
@@ -84,7 +84,7 @@ function SoundManager(smURL, smID) {
84
84
  'required': true
85
85
  },
86
86
  'mp4': {
87
- 'related': ['aac','m4a'],
87
+ 'related': ['aac','m4a','m4b'],
88
88
  'type': ['audio/mp4; codecs="mp4a.40.2"', 'audio/aac', 'audio/x-m4a', 'audio/MP4A-LATM', 'audio/mpeg4-generic'],
89
89
  'required': false
90
90
  },
@@ -101,7 +101,7 @@ function SoundManager(smURL, smID) {
101
101
  this.id = (smID || 'sm2movie');
102
102
  this.debugID = 'soundmanager-debug';
103
103
  this.debugURLParam = /([#?&])debug=1/i;
104
- this.versionNumber = 'V2.97a.20120624';
104
+ this.versionNumber = 'V2.97a.20120916';
105
105
  this.version = null;
106
106
  this.movieURL = null;
107
107
  this.altURL = null;
@@ -128,7 +128,7 @@ function SoundManager(smURL, smID) {
128
128
  };
129
129
  this.hasHTML5 = (function() {
130
130
  try {
131
- return (typeof Audio !== 'undefined' && typeof new Audio().canPlayType !== 'undefined');
131
+ return (typeof Audio !== 'undefined' && typeof (_isOpera && opera.version() < 10 ? new Audio(null) : new Audio()).canPlayType !== 'undefined');
132
132
  } catch(e) {
133
133
  return false;
134
134
  }
@@ -145,12 +145,12 @@ function SoundManager(smURL, smID) {
145
145
  _is_iDevice = _ua.match(/(ipad|iphone|ipod)/i), _isIE = _ua.match(/msie/i), _isWebkit = _ua.match(/webkit/i), _isSafari = (_ua.match(/safari/i) && !_ua.match(/chrome/i)), _isOpera = (_ua.match(/opera/i)),
146
146
  _mobileHTML5 = (_ua.match(/(mobile|pre\/|xoom)/i) || _is_iDevice),
147
147
  _isBadSafari = (!_wl.match(/usehtml5audio/i) && !_wl.match(/sm2\-ignorebadua/i) && _isSafari && !_ua.match(/silk/i) && _ua.match(/OS X 10_6_([3-7])/i)),
148
- _hasConsole = (typeof console !== 'undefined' && typeof console.log !== 'undefined'), _isFocused = (typeof _doc.hasFocus !== 'undefined'?_doc.hasFocus():null), _tryInitOnFocus = (_isSafari && (typeof _doc.hasFocus === 'undefined' || !_doc.hasFocus())), _okToDisable = !_tryInitOnFocus, _flashMIME = /(mp3|mp4|mpa|m4a)/i,
148
+ _hasConsole = (typeof console !== 'undefined' && typeof console.log !== 'undefined'), _isFocused = (typeof _doc.hasFocus !== 'undefined'?_doc.hasFocus():null), _tryInitOnFocus = (_isSafari && (typeof _doc.hasFocus === 'undefined' || !_doc.hasFocus())), _okToDisable = !_tryInitOnFocus, _flashMIME = /(mp3|mp4|mpa|m4a|m4b)/i,
149
149
  _emptyURL = 'about:blank',
150
150
  _overHTTP = (_doc.location?_doc.location.protocol.match(/http/i):null),
151
151
  _http = (!_overHTTP ? 'http:/'+'/' : ''),
152
- _netStreamMimeTypes = /^\s*audio\/(?:x-)?(?:mpeg4|aac|flv|mov|mp4||m4v|m4a|mp4v|3gp|3g2)\s*(?:$|;)/i,
153
- _netStreamTypes = ['mpeg4', 'aac', 'flv', 'mov', 'mp4', 'm4v', 'f4v', 'm4a', 'mp4v', '3gp', '3g2'],
152
+ _netStreamMimeTypes = /^\s*audio\/(?:x-)?(?:mpeg4|aac|flv|mov|mp4||m4v|m4a|m4b|mp4v|3gp|3g2)\s*(?:$|;)/i,
153
+ _netStreamTypes = ['mpeg4', 'aac', 'flv', 'mov', 'mp4', 'm4v', 'f4v', 'm4a', 'm4b', 'mp4v', '3gp', '3g2'],
154
154
  _netStreamPattern = new RegExp('\\.(' + _netStreamTypes.join('|') + ')(\\?.*)?$', 'i');
155
155
  this.mimePattern = /^\s*audio\/(?:x-)?(?:mp(?:eg|3))\s*(?:$|;)/i;
156
156
  this.useAltURL = !_overHTTP;
@@ -175,10 +175,17 @@ function SoundManager(smURL, smID) {
175
175
  }
176
176
  }
177
177
  this.setup = function(options) {
178
+ var noURL = (!_s.url);
178
179
  if (typeof options !== 'undefined' && _didInit && _needsFlash && _s.ok() && (typeof options.flashVersion !== 'undefined' || typeof options.url !== 'undefined')) {
179
180
  _complain(_str('setupLate'));
180
181
  }
181
182
  _assign(options);
183
+ if (noURL && _didDCLoaded && typeof options.url !== 'undefined') {
184
+ _s.beginDelayedInit();
185
+ }
186
+ if (!_didDCLoaded && typeof options.url !== 'undefined' && _doc.readyState === 'complete') {
187
+ setTimeout(_domContentLoaded, 1);
188
+ }
182
189
  return _s;
183
190
  };
184
191
  this.ok = function() {
@@ -606,7 +613,7 @@ function SoundManager(smURL, smID) {
606
613
  return _t;
607
614
  }
608
615
  _iO = _t._iO;
609
- _lastURL = _t.url;
616
+ _lastURL = (_t.url && _t.url.toString ? _t.url.toString() : null);
610
617
  _t.loaded = false;
611
618
  _t.readyState = 1;
612
619
  _t.playState = 0;
@@ -641,6 +648,7 @@ function SoundManager(smURL, smID) {
641
648
  _catchError({type:'SMSOUND_LOAD_JS_EXCEPTION', fatal:true});
642
649
  }
643
650
  }
651
+ _t.url = _iO.url;
644
652
  return _t;
645
653
  };
646
654
  this.unload = function() {
@@ -690,8 +698,11 @@ function SoundManager(smURL, smID) {
690
698
  if (!oOptions) {
691
699
  oOptions = {};
692
700
  }
693
- _t._iO = _mixin(oOptions, _t._iO);
701
+ if (_t.url) {
702
+ _t._iO.url = _t.url;
703
+ }
694
704
  _t._iO = _mixin(_t._iO, _t.options);
705
+ _t._iO = _mixin(oOptions, _t._iO);
695
706
  _t._iO.url = _parseURL(_t._iO.url);
696
707
  _t.instanceOptions = _t._iO;
697
708
  if (_t._iO.serverURL && !_t.connected) {
@@ -714,6 +725,9 @@ function SoundManager(smURL, smID) {
714
725
  if (exit !== null) {
715
726
  return exit;
716
727
  }
728
+ if (oOptions.url && oOptions.url !== _t.url) {
729
+ _t.load(_t._iO);
730
+ }
717
731
  if (!_t.loaded) {
718
732
  if (_t.readyState === 0) {
719
733
  if (!_t.isHTML5) {
@@ -734,7 +748,7 @@ function SoundManager(smURL, smID) {
734
748
  if (!_t.isHTML5 && _fV === 9 && _t.position > 0 && _t.position === _t.duration) {
735
749
  oOptions.position = 0;
736
750
  }
737
- if (_t.paused && _t.position && _t.position > 0) {
751
+ if (_t.paused && _t.position >= 0 && (!_t._iO.serverURL || _t.position > 0)) {
738
752
  _t.resume();
739
753
  } else {
740
754
  _t._iO = _mixin(oOptions, _t._iO);
@@ -851,7 +865,7 @@ function SoundManager(smURL, smID) {
851
865
  }
852
866
  var original_pos,
853
867
  position, position1K,
854
- offset = (_t.isHTML5 ? Math.max(nMsecOffset,0) : Math.min(_t.duration || _t._iO.duration, Math.max(nMsecOffset, 0)));
868
+ offset = (_t.isHTML5 ? Math.max(nMsecOffset, 0) : Math.min(_t.duration || _t._iO.duration, Math.max(nMsecOffset, 0)));
855
869
  original_pos = _t.position;
856
870
  _t.position = offset;
857
871
  position1K = _t.position/1000;
@@ -1170,8 +1184,8 @@ function SoundManager(smURL, smID) {
1170
1184
  };
1171
1185
  this._get_html5_duration = function() {
1172
1186
  var _iO = _t._iO,
1173
- d = (_t._a ? _t._a.duration*1000 : (_iO ? _iO.duration : undefined)),
1174
- result = (d && !isNaN(d) && d !== Infinity ? d : (_iO ? _iO.duration : null));
1187
+ d = (_t._a && _t._a.duration ? _t._a.duration*1000 : (_iO && _iO.duration ? _iO.duration : null)),
1188
+ result = (d && !isNaN(d) && d !== Infinity ? d : null);
1175
1189
  return result;
1176
1190
  };
1177
1191
  this._apply_loop = function(a, nLoops) {
@@ -1207,7 +1221,7 @@ function SoundManager(smURL, smID) {
1207
1221
  if (_iO.autoLoad || _iO.autoPlay) {
1208
1222
  _t._a = new Audio(_iO.url);
1209
1223
  } else {
1210
- _t._a = (_isOpera ? new Audio(null) : new Audio());
1224
+ _t._a = (_isOpera && opera.version() < 10 ? new Audio(null) : new Audio());
1211
1225
  }
1212
1226
  _a = _t._a;
1213
1227
  _a._called_load = false;
@@ -1324,15 +1338,12 @@ function SoundManager(smURL, smID) {
1324
1338
  _t.bytesTotal = nBytesTotal;
1325
1339
  _t.duration = Math.floor(nDuration);
1326
1340
  _t.bufferLength = nBufferLength;
1327
- if (!_iO.isMovieStar) {
1341
+ if (!_t.isHTML5 && !_iO.isMovieStar) {
1328
1342
  if (_iO.duration) {
1329
1343
  _t.durationEstimate = (_t.duration > _iO.duration) ? _t.duration : _iO.duration;
1330
1344
  } else {
1331
1345
  _t.durationEstimate = parseInt((_t.bytesTotal / _t.bytesLoaded) * _t.duration, 10);
1332
1346
  }
1333
- if (typeof _t.durationEstimate === 'undefined') {
1334
- _t.durationEstimate = _t.duration;
1335
- }
1336
1347
  } else {
1337
1348
  _t.durationEstimate = _t.duration;
1338
1349
  }
@@ -1391,7 +1402,7 @@ function SoundManager(smURL, smID) {
1391
1402
  this._oncaptiondata = function(oData) {
1392
1403
  _t.captiondata = oData;
1393
1404
  if (_t._iO.oncaptiondata) {
1394
- _t._iO.oncaptiondata.apply(_t);
1405
+ _t._iO.oncaptiondata.apply(_t, [oData]);
1395
1406
  }
1396
1407
  };
1397
1408
  this._onmetadata = function(oMDProps, oMDData) {
@@ -1502,6 +1513,9 @@ function SoundManager(smURL, smID) {
1502
1513
  }
1503
1514
  return result;
1504
1515
  };
1516
+ function _preferFlashCheck(kind) {
1517
+ return (_s.preferFlash && _hasFlash && !_s.ignoreFlash && (typeof _s.flash[kind] !== 'undefined' && _s.flash[kind]));
1518
+ }
1505
1519
  _event = (function() {
1506
1520
  var old = (_win.attachEvent),
1507
1521
  evt = {
@@ -1509,7 +1523,8 @@ function SoundManager(smURL, smID) {
1509
1523
  remove: (old?'detachEvent':'removeEventListener')
1510
1524
  };
1511
1525
  function getArgs(oArgs) {
1512
- var args = _slice.call(oArgs), len = args.length;
1526
+ var args = _slice.call(oArgs),
1527
+ len = args.length;
1513
1528
  if (old) {
1514
1529
  args[1] = 'on' + args[1];
1515
1530
  if (len > 3) {
@@ -1540,9 +1555,6 @@ function SoundManager(smURL, smID) {
1540
1555
  'remove': remove
1541
1556
  };
1542
1557
  }());
1543
- function _preferFlashCheck(kind) {
1544
- return (_s.preferFlash && _hasFlash && !_s.ignoreFlash && (typeof _s.flash[kind] !== 'undefined' && _s.flash[kind]));
1545
- }
1546
1558
  function _html5_event(oFn) {
1547
1559
  return function(e) {
1548
1560
  var t = this._t,
@@ -1615,17 +1627,18 @@ function SoundManager(smURL, smID) {
1615
1627
  isProgress = (e.type === 'progress'),
1616
1628
  ranges = e.target.buffered,
1617
1629
  loaded = (e.loaded||0),
1618
- total = (e.total||1);
1630
+ total = (e.total||1),
1631
+ scale = 1000;
1619
1632
  t.buffered = [];
1620
1633
  if (ranges && ranges.length) {
1621
1634
  for (i=0, j=ranges.length; i<j; i++) {
1622
1635
  t.buffered.push({
1623
- 'start': ranges.start(i),
1624
- 'end': ranges.end(i)
1636
+ 'start': ranges.start(i) * scale,
1637
+ 'end': ranges.end(i) * scale
1625
1638
  });
1626
1639
  }
1627
- buffered = (ranges.end(0) - ranges.start(0));
1628
- loaded = buffered/e.target.duration;
1640
+ buffered = (ranges.end(0) - ranges.start(0)) * scale;
1641
+ loaded = buffered/(e.target.duration*scale);
1629
1642
  }
1630
1643
  if (!isNaN(loaded)) {
1631
1644
  t._onbufferchange(0);
@@ -1714,10 +1727,10 @@ function SoundManager(smURL, smID) {
1714
1727
  return result;
1715
1728
  };
1716
1729
  _testHTML5 = function() {
1717
- if (!_s.useHTML5Audio || typeof Audio === 'undefined') {
1730
+ if (!_s.useHTML5Audio || !_s.hasHTML5) {
1718
1731
  return false;
1719
1732
  }
1720
- var a = (typeof Audio !== 'undefined' ? (_isOpera ? new Audio(null) : new Audio()) : null),
1733
+ var a = (typeof Audio !== 'undefined' ? (_isOpera && opera.version() < 10 ? new Audio(null) : new Audio()) : null),
1721
1734
  item, lookup, support = {}, aF, i;
1722
1735
  function _cp(m) {
1723
1736
  var canPlay, i, j,
@@ -1727,7 +1740,7 @@ function SoundManager(smURL, smID) {
1727
1740
  return result;
1728
1741
  }
1729
1742
  if (m instanceof Array) {
1730
- for (i=0, j=m.length; i<j && !isOK; i++) {
1743
+ for (i=0, j=m.length; i<j; i++) {
1731
1744
  if (_s.html5[m[i]] || a.canPlayType(m[i]).match(_s.html5Test)) {
1732
1745
  isOK = true;
1733
1746
  _s.html5[m[i]] = true;
@@ -1995,8 +2008,6 @@ function SoundManager(smURL, smID) {
1995
2008
  if (_s.useHTML5Audio) {
1996
2009
  if (!_s.html5 || !_s.html5.canPlayType) {
1997
2010
  _s.hasHTML5 = false;
1998
- } else {
1999
- _s.hasHTML5 = true;
2000
2011
  }
2001
2012
  }
2002
2013
  }
@@ -2129,9 +2140,11 @@ function SoundManager(smURL, smID) {
2129
2140
  var remoteURL = (smURL || _s.url),
2130
2141
  localURL = (_s.altURL || remoteURL),
2131
2142
  swfTitle = 'JS/Flash audio component (SoundManager 2)',
2132
- oEmbed, oMovie, oTarget = _getDocument(), tmp, movieHTML, oEl, extraClass = _getSWFCSS(),
2133
- s, x, sClass, isRTL = null,
2134
- html = _doc.getElementsByTagName('html')[0];
2143
+ oTarget = _getDocument(),
2144
+ extraClass = _getSWFCSS(),
2145
+ isRTL = null,
2146
+ html = _doc.getElementsByTagName('html')[0],
2147
+ oEmbed, oMovie, tmp, movieHTML, oEl, s, x, sClass;
2135
2148
  isRTL = (html && html.dir && html.dir.match(/rtl/i));
2136
2149
  smID = (typeof smID === 'undefined'?_s.id:smID);
2137
2150
  function param(name, value) {
@@ -2265,6 +2278,9 @@ function SoundManager(smURL, smID) {
2265
2278
  if (_flash) {
2266
2279
  return false;
2267
2280
  }
2281
+ if (!_s.url) {
2282
+ return false;
2283
+ }
2268
2284
  _flash = _s.getMovie(_s.id);
2269
2285
  if (!_flash) {
2270
2286
  if (!_oRemoved) {
@@ -2291,6 +2307,9 @@ function SoundManager(smURL, smID) {
2291
2307
  _waitForEI = function() {
2292
2308
  var p,
2293
2309
  loadIncomplete = false;
2310
+ if (!_s.url) {
2311
+ return false;
2312
+ }
2294
2313
  if (_waitingForEI) {
2295
2314
  return false;
2296
2315
  }
@@ -2346,14 +2365,6 @@ function SoundManager(smURL, smID) {
2346
2365
  return true;
2347
2366
  };
2348
2367
  _showSupport = function() {
2349
- var item, tests = [];
2350
- if (_s.useHTML5Audio && _s.hasHTML5) {
2351
- for (item in _s.audioFormats) {
2352
- if (_s.audioFormats.hasOwnProperty(item)) {
2353
- 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)' : ''))));
2354
- }
2355
- }
2356
- }
2357
2368
  };
2358
2369
  _initComplete = function(bNoDisable) {
2359
2370
  if (_didInit) {
@@ -2490,9 +2501,6 @@ function SoundManager(smURL, smID) {
2490
2501
  } else {
2491
2502
  _catchError({type:'NO_DOM2_EVENTS', fatal:true});
2492
2503
  }
2493
- if (_doc.readyState === 'complete') {
2494
- setTimeout(_domContentLoaded,100);
2495
- }
2496
2504
  }
2497
2505
  // SM2_DEFER details: http://www.schillmania.com/projects/soundmanager2/doc/getstarted/#lazy-loading
2498
2506
  if (typeof SM2_DEFER === 'undefined' || !SM2_DEFER) {