getDuration
getDuration(id: string): number;
Get the total duration of a sound by its ID. Returns the duration in seconds. Returns 0 if the sound is not loaded.
Example
await soundManager.loadSounds([{ id: 'bells-melody', url: 'bells-melody.mp3' }]);
soundManager.play('bells-melody');
const duration = soundManager.getDuration('bells-melody');
console.log(`Total duration: ${duration}s`);
Loading sound...
Progress
00:00 / 00:00Ratio: 0.0000%
// Get progress values
soundManager.getCurrentTime('bells-melody'); // 0.0s
soundManager.getDuration('bells-melody'); // 0.0s
soundManager.getProgress('bells-melody'); // 0.000
soundManager.getProgressPercentage('bells-melody'); // 0%
Try it: Play the bells melody sound and watch the progress values update in real time.
getProgress() returns a ratio (0-1), getProgressPercentage() returns a percentage (0-100).