peaks.js icon indicating copy to clipboard operation
peaks.js copied to clipboard

init requires a mediaElement, but setSource does not?

Open larrywal opened this issue 3 years ago • 7 comments

Hi - am trying to use peaks.js to generate waveforms on the fly using WebAudio. I notice that with SetSource I can pass just a mediaURL and webAudio.audioContext. But on init, I must pass a mediaElement that contains the fileURL as its src.  Otherwise the init never seems to return.  Is this expected behavior?

larrywal avatar Nov 12 '20 03:11 larrywal

Peaks.init() should always return. If there's an error, it should call the callback parameter with an Error object. What combination of options are you passing to Peaks.init()?

chrisn avatar Nov 12 '20 15:11 chrisn

Thanks for the quick response! Here's the code I'm using. When I comment out the line audio.current!.src = fileURL then the code after init never seems to run.

image

larrywal avatar Nov 12 '20 16:11 larrywal

Thanks. Currently, Peaks.init() doesn't accept a mediaUrl option, so - as you've found - you need to set the media element's src attribute before calling Peaks.init().

I'll look into making Peaks.init() more consistent with .setSource().

chrisn avatar Nov 12 '20 17:11 chrisn

Got it - thanks much.

On Thu, Nov 12, 2020 at 9:12 AM Chris Needham [email protected] wrote:

Thanks. Currently, Peaks.init() doesn't accept a mediaUrl option, so - as you've found - you need to set the media element's src attribute before calling Peaks.init().

I'll look into making Peaks.init() more consistent with .setSource().

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/bbc/peaks.js/issues/341#issuecomment-726213978, or unsubscribe https://github.com/notifications/unsubscribe-auth/AKLRL4MUUACDF2PC5DN2XU3SPQJRTANCNFSM4TSYT7WQ .

larrywal avatar Nov 12 '20 17:11 larrywal

Never seen this notation: audio.current!.src = [...]

Trying to find documentation for that, but I fail. Is this correct? What do I have to search for, if I want to learn about this specific NOT notation?

rowild avatar Jun 21 '21 10:06 rowild

It's a TypeScript feature: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-0.html#non-null-assertion-operator

chrisn avatar Jun 21 '21 10:06 chrisn

Calling Peaks.init() with an empty <audio> element (i.e., no src attribute and no <source> elements), the callback is never invoked. See:

https://github.com/bbc/peaks.js/blob/ab1413560e24426aa55c13898b3d006b20ffc746/src/mediaelement-player.js#L75

chrisn avatar Dec 04 '22 22:12 chrisn