-
-
Notifications
You must be signed in to change notification settings - Fork 28
Open
Description
The title is self-explanatory: autoplay option is eaten by useSound constructor and is not passed to Howl constructor. It results in a sound not playing automatically
Lines 6 to 38 in c7bca5e
export function useSound( | |
url: MaybeRef<string>, | |
{ volume = 1, playbackRate = 1, soundEnabled = true, interrupt = false, autoplay = false, onload, ...delegated }: ComposableOptions = {}, | |
) { | |
const HowlConstructor = ref<HowlStatic | null>(null) | |
const isPlaying = ref<boolean>(false) | |
const duration = ref<number | null>(null) | |
const sound = ref<Howl | null>(null) | |
function handleLoad(this: Howl, soundId: number) { | |
if (typeof onload === 'function') onload.call(this, soundId) | |
duration.value = (duration.value || sound.value?.duration() || 0) * 1000 | |
if (autoplay === true) { | |
isPlaying.value = true | |
} | |
} | |
onMounted(async () => { | |
// Howler registers `Howl` and `Howler` globally when imported | |
await import('howler') | |
// Use global Howl constructor | |
HowlConstructor.value = Howl | |
sound.value = new HowlConstructor.value({ | |
src: unref(url) as string, | |
volume: unref(volume) as number, | |
rate: unref(playbackRate) as number, | |
onload: handleLoad, | |
...delegated, | |
}) | |
}) |
Metadata
Metadata
Assignees
Labels
No labels