play
play(id: string, options?: PlayOptions, skipDispatchEvent?: boolean): void;
Playback control: Manage the playback of sounds, including play, pause, resume, stop, and seek operations.
You can use PlayOptions as second argument. Click the link PlayOptions to see more.
You can use the SoundManagerConfig to configure you soundManager with default values. Click here to see more about
the SoundManagerConfig.
Example
// @ts-ignore
import introSpeach from "../../sounds/intro-text-speach.mp3";
// Above line is coming from your assets / sound folder directly as a variable, but you can
// also use a url.
import { SoundManager, type SoundManagerConfig, type PlayOptions} from 'sound-manager-ts';
const soundManager = new SoundManager();
// There are more configuration for the SoundManagerConfig.
const config: SoundManagerConfig = {
autoMuteOnHidden: true,
autoResumeOnFocus: true,
debug: true,
trackProgress: false,
};
await soundManager.loadSounds([{ id: 'intro-speach', url: 'https://www.linktospeachfile.mp3' }]); // or url: introSpeach
soundManager.play('intro-speach', {
pan: 0.5,
volume: 0.8,
playbackRate: 1.15,
createNewInstance: false,
fadeInDuration: 1,
fadeOutBeforeEndDuration: 4,
loop: true,
maxLoops: 2,
startTime: 0
}
);
// Action on stop button:
soundManager.stop('intro-speach');
PlayOptions Configuration
Edit the JSON below to customize playback options
Editable
Tip: The configuration will be merged with defaults when playing. Try adjusting values like
playbackRate or volume.