Skip to content

autoplay option is not passed to Howl constructor #54

@phzhitnikov

Description

@phzhitnikov

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

sound/src/index.ts

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions