Skip to content

EZ Web Audio / useInteractionMethods

Function: useInteractionMethods()

useInteractionMethods(key, player): Promise<void>

Defined in: index.ts:639

Attach play/stop handlers to an element for touch and mouse interactions.

Binds touchstart/mousedown to play() and touchend/mouseup/mouseleave to stop(). Automatically initializes audio on first interaction.

Parameters

key

HTMLElement

HTML element to attach handlers to

player

Player

Object with play() and stop() methods

Returns

Promise<void>

Example

typescript
import { useInteractionMethods, createOscillator } from 'ez-web-audio'

const synth = await createOscillator({ frequency: 440 })
const pianoKey = document.getElementById('key-a4')

await useInteractionMethods(pianoKey, synth)
// Now touching/clicking the element plays the synth