Flash fallback for wavesurfer.js
Note: This repository is now archived and readonly. No one should use Flash anymore and my knowledge of ActionScript has withered away :)
The purpose of wavesurfer.swf is to bring as many wavesurfer.js functionalities as possible to browser that do not support WebAudio or Canvas. It does this by mimicking the js version in Flash, using the same API.
Any browser that runs Flash. It was originally built to support IE9 - IE11 which all lack the required WebAudio support.
Wavesurfer.swf has no requirements apart from wavesurfer.js! However, we use SWFObject in the demo to embed the SWF.
Please refer to the demo folder for an example on how to implement wavesurfer.swf. Keep in mind that you cannot view the Flash version when running from your local disk. You need to run this demo on a webserver. This is a Flash security restriction.
The API is similar to the js version, although not all methods and configuration options are supported at the moment. Here's a very brief example:
var wavesurfer = new WaveSurfer.Swf('myFlashContainerid');
// ... embed the SWF on the page using any method you like
// Wait for the swf to initialize
wavesurfer.on('init', function() {
// Initialize with your own configuration object
wavesurfer.init({
waveColor: '#999999',
...
});
// And load the mp3 file
wavesurfer.load('Rick_Astley.mp3');
});
For more examples, please refer to the readme of wavesurfer.js.
Not all of the wavesurfer.js is currently supported. Below you'll find a list of everything that's supported.
option | type | default | description |
---|---|---|---|
cursorWidth |
integer | 1 |
Measured in pixels. |
cursorColor |
string | #333 |
The fill color of the cursor indicating the playhead position. |
progressColor |
string | #555 |
The fill color of the part of the waveform behind the cursor. |
waveColor |
string | #999 |
The fill color of the waveform after the cursor. |
backgroundColor |
string | #fff |
The fill color of background. |
init(options)
– Initializes with the options listed above.getCurrentTime()
– Returns current progress in seconds.getDuration()
– Returns the duration of an audio clip in seconds.isPlaying()
– Returns true if currently playing, false otherwise.getId()
– Get the idload(url, [waveformData])
– Loads audio from URL. Optionally you can supply your own waveform data.on(eventName, callback)
– Subscribes to an event. See WaveSurfer Events section below for a list.un(eventName, callback)
– Unsubscribes from an event.unAll()
– Unsubscribes from all events.pause()
– Stops playback.play([start])
– Starts playback from the current position.playPause()
– Plays if paused, pauses if playing.seekTo(progress)
– Seeks to a progress[0..1]
(0=beginning, 1=end).setVolume(newVolume)
– Sets the playback volume to a new value[0..1]
(0 = silent, 1 = maximum).stop()
– Stops and goes to the beginning.toggleMute()
– Toggles the volume on and off.exportPCM([samples])
– Get the PCM wave data as an array.
init
– The SWF has loaded and is ready to init.error
– Occurs on error. Callback will receive (string) error message.finish
– When it finishes playing.loading
– Fires continuously when loading. Callback will receive (integer) loading progress in percents [0..100].pause
– When audio is paused.play
– When play starts.ready
– When audio is loaded, decoded and the waveform drawn.seek
– On seeking. Callback will receive (float) progress [0..1].
Original Javascript version by katspaugh and others!