{ "version": "0.2.16", "name": "org.apache.cordova.media", "cordova_name": "Media", "description": "Cordova Media Plugin", "license": "Apache 2.0", "repo": "https://git-wip-us.apache.org/repos/asf/cordova-plugin-media.git", "issue": "https://issues.apache.org/jira/browse/CB/component/12320647", "keywords": [ "cordova", "media" ], "platforms": [ "android", "amazon-fireos", "ubuntu", "ios", "blackberry10", "wp7", "wp8", "windows8", "tizen" ], "engines": [], "englishdoc": "\n\n# org.apache.cordova.media\n\nThis plugin provides the ability to record and play back audio files on a device.\n\n__NOTE__: The current implementation does not adhere to a W3C\nspecification for media capture, and is provided for convenience only.\nA future implementation will adhere to the latest W3C specification\nand may deprecate the current APIs.\n\nThis plugin defines a global `Media` Constructor.\n\nAlthough in the global scope, it is not available until after the `deviceready` event.\n\n document.addEventListener(\"deviceready\", onDeviceReady, false);\n function onDeviceReady() {\n console.log(Media);\n }\n\n## Installation\n\n cordova plugin add org.apache.cordova.media\n\n## Supported Platforms\n\n- Android\n- BlackBerry 10\n- iOS\n- Windows Phone 7 and 8\n- Tizen\n- Windows 8\n\n## Windows Phone Quirks\n\n- Only one media file can be played back at a time.\n\n- There are strict restrictions on how your application interacts with other media. See the [Microsoft documentation for details][url].\n\n[url]: http://msdn.microsoft.com/en-us/library/windowsphone/develop/hh184838(v=vs.92).aspx\n\n## Media\n\n var media = new Media(src, mediaSuccess, [mediaError], [mediaStatus]);\n\n### Parameters\n\n- __src__: A URI containing the audio content. _(DOMString)_\n\n- __mediaSuccess__: (Optional) The callback that executes after a `Media` object has completed the current play, record, or stop action. _(Function)_\n\n- __mediaError__: (Optional) The callback that executes if an error occurs. _(Function)_\n\n- __mediaStatus__: (Optional) The callback that executes to indicate status changes. _(Function)_\n\n### Constants\n\nThe following constants are reported as the only parameter to the\n`mediaStatus` callback:\n\n- `Media.MEDIA_NONE` = 0;\n- `Media.MEDIA_STARTING` = 1;\n- `Media.MEDIA_RUNNING` = 2;\n- `Media.MEDIA_PAUSED` = 3;\n- `Media.MEDIA_STOPPED` = 4;\n\n### Methods\n\n- `media.getCurrentPosition`: Returns the current position within an audio file.\n\n- `media.getDuration`: Returns the duration of an audio file.\n\n- `media.play`: Start or resume playing an audio file.\n\n- `media.pause`: Pause playback of an audio file.\n\n- `media.release`: Releases the underlying operating system's audio resources.\n\n- `media.seekTo`: Moves the position within the audio file.\n\n- `media.setVolume`: Set the volume for audio playback.\n\n- `media.startRecord`: Start recording an audio file.\n\n- `media.stopRecord`: Stop recording an audio file.\n\n- `media.stop`: Stop playing an audio file.\n\n### Additional ReadOnly Parameters\n\n- __position__: The position within the audio playback, in seconds.\n - Not automatically updated during play; call `getCurrentPosition` to update.\n\n- __duration__: The duration of the media, in seconds.\n\n\n## media.getCurrentPosition\n\nReturns the current position within an audio file. Also updates the `Media` object's `position` parameter.\n\n media.getCurrentPosition(mediaSuccess, [mediaError]);\n\n### Parameters\n\n- __mediaSuccess__: The callback that is passed the current position in seconds.\n\n- __mediaError__: (Optional) The callback to execute if an error occurs.\n\n### Quick Example\n\n // Audio player\n //\n var my_media = new Media(src, onSuccess, onError);\n\n // Update media position every second\n var mediaTimer = setInterval(function () {\n // get media position\n my_media.getCurrentPosition(\n // success callback\n function (position) {\n if (position > -1) {\n console.log((position) + \" sec\");\n }\n },\n // error callback\n function (e) {\n console.log(\"Error getting pos=\" + e);\n }\n );\n }, 1000);\n\n\n## media.getDuration\n\nReturns the duration of an audio file in seconds. If the duration is unknown, it returns a value of -1.\n\n\n media.getDuration();\n\n### Quick Example\n\n // Audio player\n //\n var my_media = new Media(src, onSuccess, onError);\n\n // Get duration\n var counter = 0;\n var timerDur = setInterval(function() {\n counter = counter + 100;\n if (counter > 2000) {\n clearInterval(timerDur);\n }\n var dur = my_media.getDuration();\n if (dur > 0) {\n clearInterval(timerDur);\n document.getElementById('audio_duration').innerHTML = (dur) + \" sec\";\n }\n }, 100);\n\n\n## media.pause\n\nPauses playing an audio file.\n\n media.pause();\n\n\n### Quick Example\n\n // Play audio\n //\n function playAudio(url) {\n // Play the audio file at url\n var my_media = new Media(url,\n // success callback\n function () { console.log(\"playAudio():Audio Success\"); },\n // error callback\n function (err) { console.log(\"playAudio():Audio Error: \" + err); }\n );\n\n // Play audio\n my_media.play();\n\n // Pause after 10 seconds\n setTimeout(function () {\n media.pause();\n }, 10000);\n }\n\n\n## media.play\n\nStarts or resumes playing an audio file.\n\n media.play();\n\n\n### Quick Example\n\n // Play audio\n //\n function playAudio(url) {\n // Play the audio file at url\n var my_media = new Media(url,\n // success callback\n function () {\n console.log(\"playAudio():Audio Success\");\n },\n // error callback\n function (err) {\n console.log(\"playAudio():Audio Error: \" + err);\n }\n );\n // Play audio\n my_media.play();\n }\n\n\n### iOS Quirks\n\n- __numberOfLoops__: Pass this option to the `play` method to specify\n the number of times you want the media file to play, e.g.:\n\n var myMedia = new Media(\"http://audio.ibeat.org/content/p1rj1s/p1rj1s_-_rockGuitar.mp3\")\n myMedia.play({ numberOfLoops: 2 })\n\n- __playAudioWhenScreenIsLocked__: Pass in this option to the `play`\n method to specify whether you want to allow playback when the screen\n is locked. If set to `true` (the default value), the state of the\n hardware mute button is ignored, e.g.:\n\n var myMedia = new Media(\"http://audio.ibeat.org/content/p1rj1s/p1rj1s_-_rockGuitar.mp3\")\n myMedia.play({ playAudioWhenScreenIsLocked : false })\n\n- __order of file search__: When only a file name or simple path is\n provided, iOS searches in the `www` directory for the file, then in\n the application's `documents/tmp` directory:\n\n var myMedia = new Media(\"audio/beer.mp3\")\n myMedia.play() // first looks for file in www/audio/beer.mp3 then in /documents/tmp/audio/beer.mp3\n\n## media.release\n\nReleases the underlying operating system's audio resources.\nThis is particularly important for Android, since there are a finite amount of\nOpenCore instances for media playback. Applications should call the `release`\nfunction for any `Media` resource that is no longer needed.\n\n media.release();\n\n\n### Quick Example\n\n // Audio player\n //\n var my_media = new Media(src, onSuccess, onError);\n\n my_media.play();\n my_media.stop();\n my_media.release();\n\n\n## media.seekTo\n\nSets the current position within an audio file.\n\n media.seekTo(milliseconds);\n\n### Parameters\n\n- __milliseconds__: The position to set the playback position within the audio, in milliseconds.\n\n\n### Quick Example\n\n // Audio player\n //\n var my_media = new Media(src, onSuccess, onError);\n my_media.play();\n // SeekTo to 10 seconds after 5 seconds\n setTimeout(function() {\n my_media.seekTo(10000);\n }, 5000);\n\n\n### BlackBerry 10 Quirks\n\n- Not supported on BlackBerry OS 5 devices.\n\n## media.setVolume\n\nSet the volume for an audio file.\n\n media.setVolume(volume);\n\n### Parameters\n\n- __volume__: The volume to set for playback. The value must be within the range of 0.0 to 1.0.\n\n### Supported Platforms\n\n- Android\n- iOS\n\n### Quick Example\n\n // Play audio\n //\n function playAudio(url) {\n // Play the audio file at url\n var my_media = new Media(url,\n // success callback\n function() {\n console.log(\"playAudio():Audio Success\");\n },\n // error callback\n function(err) {\n console.log(\"playAudio():Audio Error: \"+err);\n });\n\n // Play audio\n my_media.play();\n\n // Mute volume after 2 seconds\n setTimeout(function() {\n my_media.setVolume('0.0');\n }, 2000);\n\n // Set volume to 1.0 after 5 seconds\n setTimeout(function() {\n my_media.setVolume('1.0');\n }, 5000);\n }\n\n\n## media.startRecord\n\nStarts recording an audio file.\n\n media.startRecord();\n\n### Supported Platforms\n\n- Android\n- iOS\n- Windows Phone 7 and 8\n- Windows 8\n\n### Quick Example\n\n // Record audio\n //\n function recordAudio() {\n var src = \"myrecording.mp3\";\n var mediaRec = new Media(src,\n // success callback\n function() {\n console.log(\"recordAudio():Audio Success\");\n },\n\n // error callback\n function(err) {\n console.log(\"recordAudio():Audio Error: \"+ err.code);\n });\n\n // Record audio\n mediaRec.startRecord();\n }\n\n\n### Android Quirks\n\n- Android devices record audio in Adaptive Multi-Rate format. The specified file should end with a _.amr_ extension.\n- The hardware volume controls are wired up to the media volume while any Media objects are alive. Once the last created Media object has `release()` called on it, the volume controls revert to their default behaviour. The controls are also reset on page navigation, as this releases all Media objects.\n\n### iOS Quirks\n\n- iOS only records to files of type _.wav_ and returns an error if the file name extension is not correct.\n\n- If a full path is not provided, the recording is placed in the application's `documents/tmp` directory. This can be accessed via the `File` API using `LocalFileSystem.TEMPORARY`. Any subdirectory specified at record time must already exist.\n\n- Files can be recorded and played back using the documents URI:\n\n var myMedia = new Media(\"documents://beer.mp3\")\n\n### Windows 8 Quirks\n\n- If a full path is not provided, the recording is placed in the AppData/temp directory. This can be accessed via the `File` API using `LocalFileSystem.TEMPORARY` or 'ms-appdata:///temp/' URI.\n\n- Any subdirectory specified at record time must already exist.\n\n### Tizen Quirks\n\n- Not supported on Tizen devices.\n\n## media.stop\n\nStops playing an audio file.\n\n media.stop();\n\n### Quick Example\n\n // Play audio\n //\n function playAudio(url) {\n // Play the audio file at url\n var my_media = new Media(url,\n // success callback\n function() {\n console.log(\"playAudio():Audio Success\");\n },\n // error callback\n function(err) {\n console.log(\"playAudio():Audio Error: \"+err);\n }\n );\n\n // Play audio\n my_media.play();\n\n // Pause after 10 seconds\n setTimeout(function() {\n my_media.stop();\n }, 10000);\n }\n\n\n## media.stopRecord\n\nStops recording an audio file.\n\n media.stopRecord();\n\n### Supported Platforms\n\n- Android\n- iOS\n- Windows Phone 7 and 8\n- Windows 8\n\n### Quick Example\n\n // Record audio\n //\n function recordAudio() {\n var src = \"myrecording.mp3\";\n var mediaRec = new Media(src,\n // success callback\n function() {\n console.log(\"recordAudio():Audio Success\");\n },\n\n // error callback\n function(err) {\n console.log(\"recordAudio():Audio Error: \"+ err.code);\n }\n );\n\n // Record audio\n mediaRec.startRecord();\n\n // Stop recording after 10 seconds\n setTimeout(function() {\n mediaRec.stopRecord();\n }, 10000);\n }\n\n\n### Tizen Quirks\n\n- Not supported on Tizen devices.\n\n## MediaError\n\nA `MediaError` object is returned to the `mediaError` callback\nfunction when an error occurs.\n\n### Properties\n\n- __code__: One of the predefined error codes listed below.\n\n- __message__: An error message describing the details of the error.\n\n### Constants\n\n- `MediaError.MEDIA_ERR_ABORTED` = 1\n- `MediaError.MEDIA_ERR_NETWORK` = 2\n- `MediaError.MEDIA_ERR_DECODE` = 3\n- `MediaError.MEDIA_ERR_NONE_SUPPORTED` = 4\n\n" }