Skip to content

[useAudio] state.duration is always 0 when preload audio in nextjs #2642

@zzddlalala

Description

@zzddlalala

What is the current behavior?

Steps to reproduce it and if possible a minimal demo of the problem. Your bug will get fixed much faster if we can run your code and it doesn't have extra dependencies other than react-use. Paste the link to your JSFiddle or CodeSandbox example below:

In nextjs, i used this hook useAudio with props preload: 'metadata', the strange thing is that the state.duration is always 0.
You can see details in the following sandbox.
https://codesandbox.io/p/devbox/react-use-audio-j7fwpm
What is the expected behavior?
make state.duration normal, it seems that the onDurationChange event is not trigger because the audio is loaded at early moment which the onDurationChange event is not added.

A little about versions:

  • OS:
  • Browser (vendor and version):
  • React:
  • react-use:
  • Did this worked in the previous package version?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions