Created: 2012-03-22 18:26
Updated: 2014-06-04 19:59

GWT Audio API Wrapper for Mozilla Audio Data API

This GWT library provides classes, interfaces, and methods to implement the Mozilla Audio Data API, and provides compatibility also with the WebKit/W3C Web Audio API (but does not provide a full implementation of that API). For functional compatibility with the Web Audio API, two methods not part of the Mozilla Audio Data API are included here: Audio.connect() and Audio.disconnect().

The AudioText2 code provides a working example of a simple tone generator, which has been tested to work in both Firefox and Chromium. This just shows a "Play" button which triggers a tone at 440Hz (A above middle C in standard tuning). The code can be seen in action in a post on my Wordpress.

The directory structure and library import files are set up to work in Eclipse.



public class Audio extends
  implements HasAudioAvailableHandlers           // <-- for reference implementation

constructor is protected

public static Audio createIfSupported()          // overrides
public void setup(int channels, int sampleRate)  // mozSetup(channels, sampleRate)
public void writeAudio(float[] buffer)           // mozWriteAudio(buffer)
public int currentSampleOffset()                 // mozCurrentSampleOffset()
public int getChannels()                         // returns mozChannels
public int getSampleRate()                       // returns mozSampleRate
public int getFrameBufferLength()                // returns mozFrameBufferLength
public void connect()                            // for Webkit compatibility
public void disconnect()                         // for Webkit compatibility
public HandlerRegistration addAudioAvalableHandler(AudioAvailableHandler h) // reference implementation


public class AudioAvailableEvent extends DomEvent<AudioAvailableHandler>

uses constructor from super

public DomEvent.Type<AudioAvailableHandler> getType()   // overrides
public DomEvent.Type<AudioAvailableHandler> getAvailableType()   // overrides
protected void dispatch(AudioAvailableHandler handler)  // overrides


public interface AudioAvailableHandler extends EventHandler


public void onAudioAvailable(AudioAvailableEvent e)


public interface HasAudioAvailableHandlers


public HandlerRegistration 
    addAudioAvailableHandler(AudioAvailableHandler h)

Notes on WebKit Compatibility

WebKit compatibility is provided through a JavaScript library moz2wk-audio.js which is found in the Audio/src/edu/jsu/leathrum/audio/shared/public directory and is included automatically in any project importing the library through the Audio.gwt.xml file in the Audio/src/edu/jsu/leathrum/audio/shared directory. This JavaScript library provides implementations of the Mozilla Audio Data API methods and properties (attached to the WebKit HTMLAudioElement object) when in a WebKit browser environment, and provides empty implementations of the connect() and disconnect() methods otherwise.


Aside from the authors responsible for writing the API documentation cited above, I should note that the tone generator code was based on both the tone generator code in the Mozilla Audio Data API page and the tone generator for the Web Audio API at

Cookies help us deliver our services. By using our services, you agree to our use of cookies Learn more