bbc / peaks.js

JavaScript UI component for interacting with audio waveforms
https://waveform.prototyping.bbc.co.uk
GNU Lesser General Public License v3.0
3.21k stars 280 forks source link

init requires a mediaElement, but setSource does not? #341

Open larrywal opened 3 years ago

larrywal commented 3 years ago

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?

chrisn commented 3 years ago

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()?

larrywal commented 3 years ago

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

chrisn commented 3 years ago

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().

larrywal commented 3 years ago

Got it - thanks much.

On Thu, Nov 12, 2020 at 9:12 AM Chris Needham notifications@github.com 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 .

rowild commented 3 years ago

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?

chrisn commented 3 years ago

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

chrisn commented 1 year ago

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