Media

The Media object provides the ability to record and play back audio files on a device.

var media = new Media(src, mediaSuccess, [mediaError]);

Note: The current implementation does not adhere to a W3C specification for media capture, and is provided for convenience only. A future implementation will adhere to the latest W3C specification and may deprecate the current APIs.

Parameters

  • src: A URI containing the audio content. (DOMString)
  • mediaSuccess: (Optional) The callback that is invoked after a Media object has completed the current play/record or stop action. (Function)
  • mediaError: (Optional) The callback that is invoked if there was an error. (Function)

Methods

  • media.getCurrentPosition: Returns the current position within an audio file.
  • media.getDuration: Returns the duration of an audio file.
  • media.play: Start or resume playing audio file.
  • media.pause: Pause playing audio file.
  • media.release: Releases the underlying OS'es audio resources.
  • media.startRecord: Start recording audio file.
  • media.stopRecord: Stop recording audio file.
  • media.stop: Stop playing audio file.

Supported Platforms

  • Android
  • iOS

iOS Quirks

  • The callback functions must be global in scope (version 0.9.4 and earlier).
  • In the media constructor iOS calls a prepare method to load the file into the player in preparation for playing. An optional downloadCompleteCallback can be passed as the final parameter to the Media constructor. It will be called when the the call to prepare completes.