scottschiller / SoundManager2

A JavaScript Sound API supporting MP3, MPEG4 and HTML5 audio + RTMP, providing reliable cross-browser/platform audio control in as little as 12 KB. BSD licensed.
http://www.schillmania.com/projects/soundmanager2/
Other
4.99k stars 769 forks source link

how to use waveformData function #165

Open xiaoxiaodexueyin opened 7 years ago

xiaoxiaodexueyin commented 7 years ago

i read the api, it said when whileplaying() fired can get the waveformData, but i write on the console, it returned null.

could you please tell me how to use the waveformdata? or any function can help me to get the audio's waveform data array when i have load it fully? because i need to draw the audio wave with canvas.....

thanks!

scottschiller commented 7 years ago

Hi there,

Sorry this isn't better documented - the waveformData bits rely on using Flash 9 under the hood, which SM2 by default has moved away from given that Flash is being officially retired in a few years.

There are also a number of cross-domain / security restrictions on accessing this data from Flash - but if you do want to try it, you can play around with preferFlash: true and flashVersion: 9 to get SM2 to use Flash 9 under the hood for audio playback.

Live demo here - note that you will need to unblock and allow the Flash plugin to run immediately on page load (basically), otherwise it will fall back to HTML5 and no visualizations will work during playback. http://www.schillmania.com/projects/soundmanager2/demo/360-player/canvas-visualization.html#hifi=1

These days, support for this data should be pretty reliable from HTML5 via the Web Audio API; I'll make a note to revisit it. In previous years, support was quite buggy between Firefox, Safari, Chrome and non-existent in IE.