|
1 | 1 | /*! |
2 | | - * howler.js v2.0.2 |
| 2 | + * howler.js v2.0.3 |
3 | 3 | * howlerjs.com |
4 | 4 | * |
5 | | - * (c) 2013-2016, James Simpson of GoldFire Studios |
| 5 | + * (c) 2013-2017, James Simpson of GoldFire Studios |
6 | 6 | * goldfirestudios.com |
7 | 7 | * |
8 | 8 | * MIT License |
|
30 | 30 | init: function() { |
31 | 31 | var self = this || Howler; |
32 | 32 |
|
| 33 | + // Create a global ID counter. |
| 34 | + self._counter = 0; |
| 35 | + |
33 | 36 | // Internal properties. |
34 | 37 | self._codecs = {}; |
35 | 38 | self._howls = []; |
|
559 | 562 | } |
560 | 563 | } |
561 | 564 |
|
| 565 | + // Log a warning if no extension was found. |
| 566 | + if (!ext) { |
| 567 | + console.warn('No file extension was found. Consider using the "format" property or specify an extension.'); |
| 568 | + } |
| 569 | + |
562 | 570 | // Check if this extension is available. |
563 | | - if (Howler.codecs(ext)) { |
| 571 | + if (ext && Howler.codecs(ext)) { |
564 | 572 | url = self._src[i]; |
565 | 573 | break; |
566 | 574 | } |
|
723 | 731 | playWebAudio(); |
724 | 732 | } else { |
725 | 733 | // Wait for the audio to load and then begin playback. |
726 | | - self.once(isRunning ? 'load' : 'resume', playWebAudio, isRunning ? sound._id : null); |
| 734 | + var event = !isRunning && self._state === 'loaded' ? 'resume' : 'load'; |
| 735 | + self.once(event, playWebAudio, isRunning ? sound._id : null); |
727 | 736 |
|
728 | 737 | // Cancel the end timer. |
729 | 738 | self._clearTimer(sound._id); |
|
735 | 744 | node.muted = sound._muted || self._muted || Howler._muted || node.muted; |
736 | 745 | node.volume = sound._volume * Howler.volume(); |
737 | 746 | node.playbackRate = sound._rate; |
| 747 | + node.play(); |
738 | 748 |
|
739 | | - setTimeout(function() { |
740 | | - node.play(); |
741 | | - |
742 | | - // Setup the new end timer. |
743 | | - if (timeout !== Infinity) { |
744 | | - self._endTimers[sound._id] = setTimeout(self._ended.bind(self, sound), timeout); |
745 | | - } |
| 749 | + // Setup the new end timer. |
| 750 | + if (timeout !== Infinity) { |
| 751 | + self._endTimers[sound._id] = setTimeout(self._ended.bind(self, sound), timeout); |
| 752 | + } |
746 | 753 |
|
747 | | - if (!internal) { |
748 | | - self._emit('play', sound._id); |
749 | | - } |
750 | | - }, 0); |
| 754 | + if (!internal) { |
| 755 | + self._emit('play', sound._id); |
| 756 | + } |
751 | 757 | }; |
752 | 758 |
|
753 | 759 | // Play immediately if ready, or wait for the 'canplaythrough'e vent. |
|
1135 | 1141 | } |
1136 | 1142 |
|
1137 | 1143 | // When the fade is complete, stop it and fire event. |
1138 | | - if (vol === to) { |
| 1144 | + if ((to < from && vol <= to) || (to > from && vol >= to)) { |
1139 | 1145 | clearInterval(sound._interval); |
1140 | 1146 | sound._interval = null; |
1141 | | - self.volume(vol, soundId); |
| 1147 | + self.volume(to, soundId); |
1142 | 1148 | self._emit('fade', soundId); |
1143 | 1149 | } |
1144 | 1150 | }.bind(self, ids[i], sound), stepLen); |
|
1468 | 1474 | // Stop the sound if it is currently playing. |
1469 | 1475 | if (!sounds[i]._paused) { |
1470 | 1476 | self.stop(sounds[i]._id); |
1471 | | - self._emit('end', sounds[i]._id); |
1472 | 1477 | } |
1473 | 1478 |
|
1474 | 1479 | // Remove the source or disconnect. |
1475 | 1480 | if (!self._webAudio) { |
1476 | 1481 | // Set the source to 0-second silence to stop any downloading. |
1477 | | - sounds[i]._node.src = 'data:audio/wav;base64,UklGRiQAAABXQVZFZm10IBAAAAABAAEARKwAAIhYAQACABAAZGF0YQAAAAA='; |
| 1482 | + sounds[i]._node.src = 'data:audio/wav;base64,UklGRigAAABXQVZFZm10IBIAAAABAAEARKwAAIhYAQACABAAAABkYXRhAgAAAAEA'; |
1478 | 1483 |
|
1479 | 1484 | // Remove any event listeners. |
1480 | 1485 | sounds[i]._node.removeEventListener('error', sounds[i]._errorFn, false); |
|
1890 | 1895 | self._sprite = '__default'; |
1891 | 1896 |
|
1892 | 1897 | // Generate a unique ID for this sound. |
1893 | | - self._id = Math.round(Date.now() * Math.random()); |
| 1898 | + self._id = ++Howler._counter; |
1894 | 1899 |
|
1895 | 1900 | // Add itself to the parent's pool. |
1896 | 1901 | parent._sounds.push(self); |
|
1960 | 1965 | self._sprite = '__default'; |
1961 | 1966 |
|
1962 | 1967 | // Generate a new ID so that it isn't confused with the previous sound. |
1963 | | - self._id = Math.round(Date.now() * Math.random()); |
| 1968 | + self._id = ++Howler._counter; |
1964 | 1969 |
|
1965 | 1970 | return self; |
1966 | 1971 | }, |
|
2192 | 2197 | /*! |
2193 | 2198 | * Spatial Plugin - Adds support for stereo and 3D audio where Web Audio is supported. |
2194 | 2199 | * |
2195 | | - * howler.js v2.0.2 |
| 2200 | + * howler.js v2.0.3 |
2196 | 2201 | * howlerjs.com |
2197 | 2202 | * |
2198 | | - * (c) 2013-2016, James Simpson of GoldFire Studios |
| 2203 | + * (c) 2013-2017, James Simpson of GoldFire Studios |
2199 | 2204 | * goldfirestudios.com |
2200 | 2205 | * |
2201 | 2206 | * MIT License |
|
0 commit comments