You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+23-5
Original file line number
Diff line number
Diff line change
@@ -225,6 +225,8 @@ Fires when the sound's playback rate has changed. The first parameter is the ID
225
225
Fires when the sound has been seeked. The first parameter is the ID of the sound.
226
226
#### onfade `Function`
227
227
Fires when the current sound finishes fading in/out. The first parameter is the ID of the sound.
228
+
#### onunlock `Function`
229
+
Fires when audio has been automatically unlocked through a touch/click event.
228
230
229
231
230
232
### Methods
@@ -285,19 +287,19 @@ Get the duration of the audio source. Will return 0 until after the `load` event
285
287
286
288
#### on(event, function, [id])
287
289
Listen for events. Multiple events can be added by calling this multiple times.
288
-
***event**: `String` Name of event to fire/set (`load`, `loaderror`, `playerror`, `play`, `end`, `pause`, `stop`, `mute`, `volume`, `rate`, `seek`, `fade`).
290
+
***event**: `String` Name of event to fire/set (`load`, `loaderror`, `playerror`, `play`, `end`, `pause`, `stop`, `mute`, `volume`, `rate`, `seek`, `fade`, `unlock`).
289
291
***function**: `Function` Define function to fire on event.
290
292
***id**: `Number``optional` Only listen to events for this sound id.
291
293
292
294
#### once(event, function, [id])
293
295
Same as `on`, but it removes itself after the callback is fired.
294
-
***event**: `String` Name of event to fire/set (`load`, `loaderror`, `playerror`, `play`, `end`, `pause`, `stop`, `mute`, `volume`, `rate`, `seek`, `fade`).
296
+
***event**: `String` Name of event to fire/set (`load`, `loaderror`, `playerror`, `play`, `end`, `pause`, `stop`, `mute`, `volume`, `rate`, `seek`, `fade`, `unlock`).
295
297
***function**: `Function` Define function to fire on event.
296
298
***id**: `Number``optional` Only listen to events for this sound id.
297
299
298
300
#### off(event, [function], [id])
299
301
Remove event listener that you've set. Call without parameters to remove all events.
300
-
***event**: `String` Name of event (`load`, `loaderror`, `playerror`, `play`, `end`, `pause`, `stop`, `mute`, `volume`, `rate`, `seek`, `fade`).
302
+
***event**: `String` Name of event (`load`, `loaderror`, `playerror`, `play`, `end`, `pause`, `stop`, `mute`, `volume`, `rate`, `seek`, `fade`, `unlock`).
301
303
***function**: `Function``optional` The listener to remove. Omit this to remove all events of type.
302
304
***id**: `Number``optional` Only remove events for this sound id.
303
305
@@ -415,13 +417,29 @@ Get/set the direction the listener is pointing in the 3D cartesian space. A fron
415
417
***zUp**: `Number` The z-orientation of the top of the listener.
416
418
417
419
418
-
### Mobile Playback
419
-
By default, audio on iOS, Android, etc is locked until a sound is played within a user interaction, and then it plays normally the rest of the page session ([Apple documentation](https://developer.apple.com/library/safari/documentation/audiovideo/conceptual/using_html5_audio_video/PlayingandSynthesizingSounds/PlayingandSynthesizingSounds.html)). The default behavior of howler.js is to attempt to silently unlock audio playback by playing an empty buffer on the first `touchend` event. This behavior can be disabled by calling:
420
+
### Mobile/Chrome Playback
421
+
By default, audio on mobile browsers and Chrome is locked until a sound is played within a user interaction, and then it plays normally the rest of the page session ([Apple documentation](https://developer.apple.com/library/safari/documentation/audiovideo/conceptual/using_html5_audio_video/PlayingandSynthesizingSounds/PlayingandSynthesizingSounds.html)). The default behavior of howler.js is to attempt to silently unlock audio playback by playing an empty buffer on the first `touchend` event. This behavior can be disabled by calling:
420
422
421
423
```javascript
422
424
Howler.mobileAutoEnable=false;
423
425
```
424
426
427
+
If you try to play audio automatically on page load, you can listen to a `playerror` event and then wait for the `unlock` event to try and play the audio again:
428
+
429
+
```javascript
430
+
var sound =newHowl({
431
+
src: ['sound.webm', 'sound.mp3'],
432
+
onplayerror:function() {
433
+
sound.once('unlock', function() {
434
+
sound.play();
435
+
});
436
+
}
437
+
});
438
+
439
+
sound.play();
440
+
```
441
+
442
+
425
443
### Dolby Audio Playback
426
444
Full support for playback of the Dolby Audio format (currently support in Edge and Safari) is included. However, you must specify that the file you are loading is `dolby` since it is in a `mp4` container.
0 commit comments