getPlaybackRate
Read the playback speed of a sound. 1 is normal speed.
getPlaybackRate(id: string): number;
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
id | string | required | ID of the sound or stream. |
Returns
number: the current rate. For an id that is not loaded you get the defaultPlaybackRate from the config, 1 by default.
Example
import { SoundHub } from 'soundhub';
const soundHub = new SoundHub();
await soundHub.loadSound('music', '/audio/theme.mp3');
soundHub.play('music', { playbackRate: 1.5 });
soundHub.getPlaybackRate('music'); // 1.5
Good to know
- While the sound plays, the value comes from the audio source itself. Otherwise it is the rate stored in the sound's play options.
- For a stream from
loadStreamit returns the media element'splaybackRate. - An id that is not loaded still logs an error and dispatches an
errorevent before the default is returned.
See also
setPlaybackRate: change the speed.PlayOptions: set the rate when you play.