leptos-use icon indicating copy to clipboard operation
leptos-use copied to clipboard

Feature request use_audio as a reactive wrapper for web audio api

Open timon-schelling opened this issue 8 months ago • 2 comments

Feature request use_audio as a reactive wrapper for web audio api.

see https://rustwasm.github.io/wasm-bindgen/examples/web-audio.html, https://developer.mozilla.org/de/docs/Web/API/Web_Audio_API

A good starting point would could be implementing simple track playing functionality based on AudioBufferSourceNode etc.

timon-schelling avatar Mar 27 '25 18:03 timon-schelling

Sounds interesting. But also quite a scope with this node based API.

How would you imagine the leptos-use implementation to be used? Can you provide sort of a pseudo rust code how you would like to be able to use it?

maccesch avatar Mar 27 '25 22:03 maccesch

Maybe start with a simple useAudioPlayer.

let ap = useAudioPlayer();
...
let track_handle = ap.load(bytearray);
...
ap.play(track_handle);
...
ap.stop(track_handle);

I have implemented something similar, but my solution is far from optimal.

A wrapper for the whole WebAudio api could center around useAudioContext. I'm not experienced enough in reactive api design to have a justified opinion on how that api should look though. Maybe some other js framework has a implementation that could be used as inspiration?

timon-schelling avatar Apr 01 '25 07:04 timon-schelling