doublesymmetry / react-native-track-player

A fully fledged audio module created for music apps. Provides audio playback, external media controls, background mode and more!
https://rntp.dev/
Apache License 2.0
3.18k stars 981 forks source link

Queue duration #2225

Closed deppaa closed 6 months ago

deppaa commented 6 months ago

Hi, I'm trying to get the queue total duration using this method, but nothing works track.duration returns undefined, ver3.2 the queue consists of web links


const getQueueTotalDuration = async () => {
    const queue = await TrackPlayer.getQueue();
    const totalDuration = queue.reduce<number>(
      (acc, track) => acc + track.duration!,
      0
    );
    return totalDuration;
  };
lovegaoshi commented 6 months ago

well RNTP is not going to magically get the duration until the resource is loaded and read; the duration value stays as undefined until its loaded to the player, or you can manually set it you need your own custom logic for this, eg ffprobe