Skip to main content

removeEventListener

removeEventListener(
type: SoundEventsEnum,
callback: (event: SoundEvent) => void,
filter?: { originalId?: string; instancePattern?: RegExp }
): void;

Remove an event listener for a specific SoundEventsEnum type. Optionally, provide a filter to narrow down the events.

ParameterTypeDescription
typeSoundEventsEnumThe event type to stop listening for
callback(event: SoundEvent) => voidThe callback function that was originally registered
filter{ originalId?: string; instancePattern?: RegExp } (optional)Filter that was used when adding the listener

Filter Options

PropertyTypeDescription
originalIdstring (optional)Only remove listeners registered for a specific sound ID
instancePatternRegExp (optional)Only remove listeners registered with a specific instance pattern

Example

import { SoundManager, SoundEventsEnum } from 'sound-manager-ts';

const soundManager = new SoundManager();

const onPlay = (event) => {
console.log('Sound played:', event);
};

// Add listener
soundManager.addEventListener(SoundEventsEnum.PLAY, onPlay);

// Remove listener
soundManager.removeEventListener(SoundEventsEnum.PLAY, onPlay);