Skip to main content

getPlaybackRate

Read the playback speed of a sound. 1 is normal speed.

getPlaybackRate(id: string): number;

Parameters​

ParameterTypeDefaultDescription
idstringrequiredID 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 loadStream it returns the media element's playbackRate.
  • An id that is not loaded still logs an error and dispatches an error event before the default is returned.

See also​