|
1478 | 1478 | // Remove any event listeners.
|
1479 | 1479 | sounds[i]._node.removeEventListener('error', sounds[i]._errorFn, false);
|
1480 | 1480 | sounds[i]._node.removeEventListener(Howler._canPlayEvent, sounds[i]._loadFn, false);
|
| 1481 | + sounds[i]._node.removeEventListener('ended', sounds[i]._endFn, false); |
1481 | 1482 | }
|
1482 | 1483 |
|
1483 | 1484 | // Empty out all of the nodes.
|
|
1926 | 1927 | self._loadFn = self._loadListener.bind(self);
|
1927 | 1928 | self._node.addEventListener(Howler._canPlayEvent, self._loadFn, false);
|
1928 | 1929 |
|
1929 |
| - // Listen for 'ended' event to let us know the sound has ended. |
1930 |
| - // Normally we'd do fine without, but this will help a Safari edge case with infinite html5 audio |
| 1930 | + // Listen for the 'ended' event on the sound to account for edge-case where |
| 1931 | + // a finite sound has a duration of Infinity. |
1931 | 1932 | self._endFn = self._endListener.bind(self);
|
1932 | 1933 | self._node.addEventListener('ended', self._endFn, false);
|
1933 | 1934 |
|
|
2013 | 2014 | _endListener: function() {
|
2014 | 2015 | var self = this;
|
2015 | 2016 | var parent = self._parent;
|
2016 |
| - |
2017 |
| - // This event should fire only when the audio ended despite being marked infinite by the browser |
2018 |
| - if (parent._duration === Infinity) { |
2019 | 2017 |
|
2020 |
| - // Update the parent duration to match the real audio duration |
| 2018 | + // Only handle the `ended`` event if the duration is Infinity. |
| 2019 | + if (parent._duration === Infinity) { |
| 2020 | + // Update the parent duration to match the real audio duration. |
2021 | 2021 | // Round up the duration to account for the lower precision in HTML5 Audio.
|
2022 | 2022 | parent._duration = Math.ceil(self._node.duration * 10) / 10;
|
2023 |
| - |
2024 |
| - // Setup a sprite that corresponds to the real duration. |
| 2023 | + |
| 2024 | + // Update the sprite that corresponds to the real duration. |
2025 | 2025 | if (parent._sprite.__default[1] === Infinity) {
|
2026 | 2026 | parent._sprite.__default[1] = parent._duration * 1000;
|
2027 | 2027 | }
|
2028 | 2028 |
|
| 2029 | + // Run the regular ended method. |
2029 | 2030 | parent._ended(self);
|
2030 | 2031 | }
|
2031 | 2032 |
|
2032 |
| - // Clear the event listener. |
| 2033 | + // Clear the event listener since the duration is now correct. |
2033 | 2034 | self._node.removeEventListener('ended', self._endFn, false);
|
2034 | 2035 | }
|
2035 | 2036 | };
|
|
0 commit comments