Skip to content

Commit

Permalink
Merge pull request #51 from E-Kuerschner/add-howler
Browse files Browse the repository at this point in the history
Add howler escape hatch
  • Loading branch information
E-Kuerschner authored Sep 28, 2020
2 parents 81495f2 + 0342081 commit 872bff7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ The options interface is identical to the [howler options](https://github.com/go
- `volume: (value: number) => number`
<br/>get/set the volume of the current sound. Volume values between 0.0 and 1.0

- `player`
<br/>an escape hatch to access the underlying Howl object in case you need to use a howler feature which is not supported by this library's API
<br/>

> #### useAudioPosition
Expand Down
7 changes: 4 additions & 3 deletions src/useAudioPlayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@ export type AudioPlayerControls = Omit<AudioPlayerContext, "player"> & {
mute: Howl["mute"] | typeof noop
volume: Howl["volume"] | typeof noop
togglePlayPause: () => void
player: Howl | null
}

export const useAudioPlayer = (options?: HowlOptions): AudioPlayerControls => {
const { player, load, ...rest } = useContext(playerContext)!

const { src, ...restOptions } = options || {}

useEffect(() => {
const { src, ...restOptions } = options || {}
// if useAudioPlayer is called without arguments
// don't do anything: the user will have access
// to the current context
if (!src) return
load({ src, ...restOptions })
}, [src, restOptions, load])
}, [options, load])

const togglePlayPause = useCallback(() => {
if (!player) return
Expand All @@ -39,6 +39,7 @@ export const useAudioPlayer = (options?: HowlOptions): AudioPlayerControls => {

return {
...rest,
player,
play: player ? player.play.bind(player) : noop,
pause: player ? player.pause.bind(player) : noop,
stop: player ? player.stop.bind(player) : noop,
Expand Down

0 comments on commit 872bff7

Please sign in to comment.