seek
seek(id: string, time: number, skipDispatchEvent?: boolean): void;
Seek to a specific time in a sound by its ID. Optionally, skip dispatching the seek event.
Example
// @ts-ignore
import bellsMelody from "../../assets/sounds/bells-melody.mp3";
import { SoundHub } from 'soundhub';
const soundHub = new SoundHub();
await soundHub.loadSound('bells-melody', bellsMelody);
// Start playing
soundHub.play('bells-melody');
// Seek to 15 seconds
soundHub.seek('bells-melody', 15);
// You can also use getCurrentTime() and getDuration() to build a progress UI
const duration = soundHub.getDuration('bells-melody');
const currentTime = soundHub.getCurrentTime('bells-melody');
console.log(`Progress: ${currentTime} / ${duration} seconds`);
Loading sound...
Seek Control
00:0000:00
// Seek to a specific time (in seconds)
soundHub.seek('bells-melody', 15);
Tip: Use
seek(id, time) to jump to any position in the audio. The time parameter is in seconds. Combine with getCurrentTime() andgetDuration() to build custom progress UIs.