This version of the documentation is outdated!
Click here for the latest released version.
Media
The
Media
object provides the ability to record and play back audio files on a device.
var media = new Media(src, mediaSuccess, [mediaError], [mediaStatus]);
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)
- mediaStatus: (Optional) The callback that is invoked to indicate status changes. (Function)
Constants
The following constants are reported as the only parameter to the mediaStatus callback function.
Media.MEDIA_NONE
= 0;Media.MEDIA_STARTING
= 1;Media.MEDIA_RUNNING
= 2;Media.MEDIA_PAUSED
= 3;Media.MEDIA_STOPPED
= 4;
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.seekTo: Moves the position within the audio file.
- media.setVolume: Set the volume for audio playback.
- media.startRecord: Start recording audio file.
- media.stopRecord: Stop recording audio file.
- media.stop: Stop playing audio file.
Additional ReadOnly Parameters
- position: The position within the audio playback in seconds.
- Not automatically updated during play, call
getCurrentPosition
to update.
- Not automatically updated during play, call
- duration: The duration of the media in seconds.
Supported Platforms
- Android
- BlackBerry WebWorks (OS 5.0 and higher)
- iOS
- Windows Phone 7.5
- Tizen
- Windows 8
Permissions
Android
app/res/xml/config.xml
<plugin name="Media" value="org.apache.cordova.AudioHandler" />
app/AndroidManifest.xml
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Bada
manifest.xml
<Privilege>
<Name>RECORDING</Name>
</Privilege>
BlackBerry WebWorks
www/plugins.xml
<plugin name="Capture" value="org.apache.cordova.media.MediaCapture" />
iOS
config.xml
<plugin name="Media" value="CDVSound" />
webOS
No permissions are required.
Windows Phone
Properties/WPAppManifest.xml
<Capabilities>
<Capability Name="ID_CAP_MEDIALIB" />
<Capability Name="ID_CAP_MICROPHONE" />
<Capability Name="ID_HW_FRONTCAMERA" />
<Capability Name="ID_CAP_ISV_CAMERA" />
<Capability Name="ID_CAP_CAMERA" />
</Capabilities>
Reference: Application Manifest for Windows Phone
Tizen
No permissions are required.
Windows Phone Quirks
Only one media file can be played back at a time.
There are strict restrictions as to how your application interacts with other media. See the Microsoft documentation for details.