<!DOCTYPE html>
<!--
    Licensed to the Apache Software Foundation (ASF) under one
    or more contributor license agreements.  See the NOTICE file
    distributed with this work for additional information
    regarding copyright ownership.  The ASF licenses this file
    to you under the Apache License, Version 2.0 (the
    "License"); you may not use this file except in compliance
    with the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing,
    software distributed under the License is distributed on an
    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    KIND, either express or implied.  See the License for the
    specific language governing permissions and limitations
    under the License.
--><html lang="en">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no, width=device-width">
        <meta name="generator" content="joDoc">
        <link href="//s3.amazonaws.com/appgyver.assets/global-assets/images/favicon.ico" rel="shortcut icon" type="image/vnd.microsoft.icon">

        <title>AppGyver Steroids API Documentation</title>

        <!-- AppGyver fonts -->
        <link type="text/css" rel="stylesheet" href="//fast.fonts.net/cssapi/aa8407d2-1212-415a-8e54-031ff8ee71fe.css">
        <link type="text/css" rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
        <link rel="stylesheet" type="text/css" href="index.css">
        <link rel="stylesheet" type="text/css" href="mobile.css" media="only screen and (max-device-width: 1024px)">
        <link rel="stylesheet" type="text/css" href="steroids.css">
        <link rel="stylesheet" type="text/css" href="service_menu.css">
        <link rel="stylesheet" type="text/css" href="prettify/prettify.css">

        <script type="text/javascript" src="https://code.jquery.com/jquery-1.11.0.min.js"></script>
        <script type="text/javascript" src="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
        <script src="https://s3.amazonaws.com/appgyver.assets/topbar.js" type="text/javascript"></script>

    </head>
    <body class="appgyver-x">

      <div class="clear" style="margin-bottom: 50px;"></div>

        <div id="cordova-wrapper">

          <div id="header">
              <h1 id="nonmobile"><a href="index.html"><strong>AppGyver Steroids</strong> API Documentation</a></h1>
              <h1 id="mobile"><a href="index.html"><strong>AppGyver Steroids</strong> API Docs</a></h1>
              <small>
                  <select><optgroup label="English" value="en">
<option value="stable">stable</option>
<option value="edge">edge</option>
<option value="3.5.8">3.5.8</option>
<option value="3.5.7">3.5.7</option>
<option value="3.5.5">3.5.5</option>
<option selected value="3.5.3">3.5.3</option>
<option value="3.5.12">3.5.12</option>
<option value="3.5.1">3.5.1</option>
<option value="3.5.0">3.5.0</option>
<option value="3.1.9">3.1.9</option>
</optgroup></select>
              </small>
          </div>
          <div id="subheader">
              <h1>Media</h1>
              <small><select><option value="Media">Media</option>
<option value="Media_parameters">      - Parameters</option>
<option value="Media_constants">      - Constants</option>
<option value="Media_methods">      - Methods</option>
<option value="Media_additional_readonly_parameters">      - Additional ReadOnly Parameters</option>
<option value="media.getCurrentPosition">media.getCurrentPosition</option>
<option value="media.getCurrentPosition_parameters">      - Parameters</option>
<option value="media.getCurrentPosition_quick_example">      - Quick Example</option>
<option value="media.getDuration">media.getDuration</option>
<option value="media.getDuration_quick_example">      - Quick Example</option>
<option value="media.pause">media.pause</option>
<option value="media.pause_quick_example">      - Quick Example</option>
<option value="media.play">media.play</option>
<option value="media.play_quick_example">      - Quick Example</option>
<option value="media.play_ios_quirks">      - iOS Quirks</option>
<option value="media.release">media.release</option>
<option value="media.release_quick_example">      - Quick Example</option>
<option value="media.seekTo">media.seekTo</option>
<option value="media.seekTo_parameters">      - Parameters</option>
<option value="media.seekTo_quick_example">      - Quick Example</option>
<option value="media.startRecord">media.startRecord</option>
<option value="media.startRecord_supported_platforms">      - Supported Platforms</option>
<option value="media.startRecord_quick_example">      - Quick Example</option>
<option value="media.startRecord_android_quirks">      - Android Quirks</option>
<option value="media.startRecord_ios_quirks">      - iOS Quirks</option>
<option value="media.stop">media.stop</option>
<option value="media.stop_quick_example">      - Quick Example</option>
<option value="media.stopRecord">media.stopRecord</option>
<option value="media.stopRecord_supported_platforms">      - Supported Platforms</option>
<option value="media.stopRecord_quick_example">      - Quick Example</option>
<option value="MediaError">MediaError</option>
<option value="MediaError_properties">      - Properties</option>
<option value="MediaError_constants">      - Constants</option></select></small>
          </div>

          <div id="sidebar">
              <div class="vertical_divider"></div>
          <h1>Steroids 3.5.3 API Reference</h1>
<ul>
<li><a href="steroids_Steroids%20Analytics%20and%20Log_index.md.html#Steroids%C2%A0Analytics%C2%A0and%C2%A0Log">Steroids Analytics and Log</a></li>
<li><a href="steroids_Steroids%20App%20and%20Device_index.md.html#Steroids%C2%A0App%C2%A0and%C2%A0Device">Steroids App and Device</a></li>
<li><a href="steroids_Steroids%20Config_index.md.html#Steroids%C2%A0Config">Steroids Config</a></li>
<li><a href="steroids_Steroids%20Events_index.md.html#Steroids%C2%A0Events">Steroids Events</a></li>
<li><a href="steroids_Steroids%20File%20System_index.md.html#Steroids%C2%A0File%C2%A0System">Steroids File System</a></li>
<li><a href="steroids_Steroids%20Media_index.md.html#Steroids%C2%A0Media">Steroids Media</a></li>
<li><a href="steroids_Steroids%20Views_index.md.html#Steroids%C2%A0Views">Steroids Views</a></li>
<li><a href="steroids_Steroids%20UI%20Components_index.md.html#Steroids%C2%A0UI%C2%A0Components">Steroids UI Components</a></li>
</ul>
<h1>Cordova 3.5.0 API Reference</h1>
<ul>
<li><a href="cordova_accelerometer_accelerometer.md.html#Accelerometer">Accelerometer</a></li>
<li><a href="cordova_camera_camera.md.html#Camera">Camera</a></li>
<li><a href="cordova_media_capture_capture.md.html#Capture">Capture</a></li>
<li><a href="cordova_compass_compass.md.html#Compass">Compass</a></li>
<li><a href="cordova_connection_connection.md.html#Connection">Connection</a></li>
<li><a href="cordova_contacts_contacts.md.html#Contacts">Contacts</a></li>
<li><a href="cordova_device_device.md.html#Device">Device</a></li>
<li><a href="cordova_events_events.md.html#Events">Events</a></li>
<li><a href="cordova_file_file.md.html#File">File</a></li>
<li><a href="cordova_file_filetransfer_filetransfer.md.html#FileTransfer">FileTransfer</a></li>
<li><a href="cordova_geolocation_geolocation.md.html#Geolocation">Geolocation</a></li>
<li><a href="cordova_globalization_globalization.md.html#Globalization">Globalization</a></li>
<li><a href="cordova_inappbrowser_inappbrowser.md.html#InAppBrowser">InAppBrowser</a></li>
<li><a href="cordova_media_media.md.html#Media">Media</a></li>
<li><a href="cordova_notification_notification.md.html#Notification">Notification</a></li>
</ul>
<h1>Guides</h1>
<ul><li><a href="_index.html">Keyword Index</a></li></ul>
</div>

          <div id="scrollable">
              <div id="content">
                  <h1><a name="Media">Media</a></h1>

<blockquote>
  <p>The <code><a href="cordova_media_media.md.html#Media">Media</a></code> object provides the ability to record and play back audio files on a device.</p>
</blockquote>

<pre class="prettyprint"><code>var media = new <a href="cordova_media_media.md.html#Media">Media</a>(src, mediaSuccess, [mediaError], [mediaStatus]);
</code></pre>

<p><strong>NOTE</strong>: 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.</p>

<h2><a name="Media_parameters">Parameters</a></h2>

<ul>
<li><p><strong>src</strong>: A URI containing the audio content. <em>(DOMString)</em></p></li>
<li><p><strong>mediaSuccess</strong>: (Optional) The callback that executes after a <code><a href="cordova_media_media.md.html#Media">Media</a></code> object has completed the current play, record, or stop action. <em>(Function)</em></p></li>
<li><p><strong>mediaError</strong>: (Optional) The callback that executes if an error occurs. <em>(Function)</em></p></li>
<li><p><strong>mediaStatus</strong>: (Optional) The callback that executes to indicate status changes. <em>(Function)</em></p></li>
</ul>

<h2><a name="Media_constants">Constants</a></h2>

<p>The following constants are reported as the only parameter to the
<code>mediaStatus</code> callback:</p>

<ul>
<li>
<code><a href="cordova_media_media.md.html#Media">Media</a>.MEDIA_NONE</code>     = 0;</li>
<li>
<code><a href="cordova_media_media.md.html#Media">Media</a>.MEDIA_STARTING</code> = 1;</li>
<li>
<code><a href="cordova_media_media.md.html#Media">Media</a>.MEDIA_RUNNING</code>  = 2;</li>
<li>
<code><a href="cordova_media_media.md.html#Media">Media</a>.MEDIA_PAUSED</code>   = 3;</li>
<li>
<code><a href="cordova_media_media.md.html#Media">Media</a>.MEDIA_STOPPED</code>  = 4;</li>
</ul>

<h2><a name="Media_methods">Methods</a></h2>

<ul>
<li><p><code><a href="cordova_media_media.md.html#media.getCurrentPosition">media.getCurrentPosition</a></code>: Returns the current position within an audio file.</p></li>
<li><p><code><a href="cordova_media_media.md.html#media.getDuration">media.getDuration</a></code>: Returns the duration of an audio file.</p></li>
<li><p><code><a href="cordova_media_media.md.html#media.play">media.play</a></code>: Start or <a href="cordova_events_events.md.html#resume">resume</a> playing an audio file.</p></li>
<li><p><code><a href="cordova_media_media.md.html#media.pause">media.pause</a></code>: Pause playback of an audio file.</p></li>
<li><p><code><a href="cordova_media_media.md.html#media.release">media.release</a></code>: Releases the underlying operating system's audio resources.</p></li>
<li><p><code><a href="cordova_media_media.md.html#media.seekTo">media.seekTo</a></code>: Moves the position within the audio file.</p></li>
<li><p><code><a href="cordova_media_media.setVolume.md.html#media.setVolume">media.setVolume</a></code>: Set the volume for audio playback.</p></li>
<li><p><code><a href="cordova_media_media.md.html#media.startRecord">media.startRecord</a></code>: Start recording an audio file.</p></li>
<li><p><code><a href="cordova_media_media.md.html#media.stopRecord">media.stopRecord</a></code>: Stop recording an audio file.</p></li>
<li><p><code><a href="cordova_media_media.md.html#media.stop">media.stop</a></code>: Stop playing an audio file.</p></li>
</ul>

<h2><a name="Media_additional_readonly_parameters">Additional ReadOnly Parameters</a></h2>

<ul>
<li>
<p><strong>position</strong>: The position within the audio playback, in seconds.</p>

<ul>
<li>Not automatically updated during play; call <code>getCurrentPosition</code> to update.</li>
</ul>
</li>
<li><p><strong>duration</strong>: The duration of the media, in seconds.</p></li>
</ul>

<hr>

<h1><a name="media.getCurrentPosition">media.getCurrentPosition</a></h1>

<p>Returns the current position within an audio file.  Also updates the <code><a href="cordova_media_media.md.html#Media">Media</a></code> object's <code>position</code> parameter.</p>

<pre class="prettyprint"><code><a href="cordova_media_media.md.html#media.getCurrentPosition">media.getCurrentPosition</a>(mediaSuccess, [mediaError]);
</code></pre>

<h2><a name="media.getCurrentPosition_parameters">Parameters</a></h2>

<ul>
<li><p><strong>mediaSuccess</strong>: The callback that is passed the current position in seconds.</p></li>
<li><p><strong>mediaError</strong>: (Optional) The callback to execute if an error occurs.</p></li>
</ul>

<h2><a name="media.getCurrentPosition_quick_example">Quick Example</a></h2>

<pre class="prettyprint"><code>// Audio player
//
var my_media = new <a href="cordova_media_media.md.html#Media">Media</a>(src, onSuccess, onError);

// Update media position every second
var mediaTimer = setInterval(function () {
    // get media position
    my_media.getCurrentPosition(
        // success callback
        function (position) {
            if (position &gt; -1) {
                console.log((position) + " sec");
            }
        },
        // error callback
        function (e) {
            console.log("Error getting pos=" + e);
        }
    );
}, 1000);
</code></pre>

<hr>

<h1><a name="media.getDuration">media.getDuration</a></h1>

<p>Returns the duration of an audio file in seconds. If the duration is unknown, it returns a value of -1.</p>

<pre class="prettyprint"><code><a href="cordova_media_media.md.html#media.getDuration">media.getDuration</a>();
</code></pre>

<h2><a name="media.getDuration_quick_example">Quick Example</a></h2>

<pre class="prettyprint"><code>// Audio player
//
var my_media = new <a href="cordova_media_media.md.html#Media">Media</a>(src, onSuccess, onError);

// Get duration
var counter = 0;
var timerDur = setInterval(function() {
    counter = counter + 100;
    if (counter &gt; 2000) {
        clearInterval(timerDur);
    }
    var dur = my_media.getDuration();
    if (dur &gt; 0) {
        clearInterval(timerDur);
        document.getElementById('audio_duration').innerHTML = (dur) + " sec";
    }
}, 100);
</code></pre>

<hr>

<h1><a name="media.pause">media.pause</a></h1>

<p>Pauses playing an audio file.</p>

<pre class="prettyprint"><code><a href="cordova_media_media.md.html#media.pause">media.pause</a>();
</code></pre>

<h2><a name="media.pause_quick_example">Quick Example</a></h2>

<pre class="prettyprint"><code>// Play audio
//
function playAudio(url) {
    // Play the audio file at url
    var my_media = new <a href="cordova_media_media.md.html#Media">Media</a>(url,
        // success callback
        function () { console.log("playAudio():Audio Success"); },
        // error callback
        function (err) { console.log("playAudio():Audio Error: " + err); }
    );

    // Play audio
    my_media.play();

    // Pause after 10 seconds
    setTimeout(function () {
        <a href="cordova_media_media.md.html#media.pause">media.pause</a>();
    }, 10000);
}
</code></pre>

<hr>

<h1><a name="media.play">media.play</a></h1>

<p>Starts or resumes playing an audio file.</p>

<pre class="prettyprint"><code><a href="cordova_media_media.md.html#media.play">media.play</a>();
</code></pre>

<h2><a name="media.play_quick_example">Quick Example</a></h2>

<pre class="prettyprint"><code>// Play audio
//
function playAudio(url) {
    // Play the audio file at url
    var my_media = new <a href="cordova_media_media.md.html#Media">Media</a>(url,
        // success callback
        function () {
            console.log("playAudio():Audio Success");
        },
        // error callback
        function (err) {
            console.log("playAudio():Audio Error: " + err);
        }
    );
    // Play audio
    my_media.play();
}
</code></pre>

<h2><a name="media.play_ios_quirks">iOS Quirks</a></h2>

<ul>
<li>
<p><strong>numberOfLoops</strong>: Pass this option to the <code>play</code> method to specify
the number of times you want the media file to play, e.g.:</p>

<pre class="prettyprint"><code>var myMedia = new <a href="cordova_media_media.md.html#Media">Media</a>("http://audio.ibeat.org/content/p1rj1s/p1rj1s_-_rockGuitar.mp3")
myMedia.play({ numberOfLoops: 2 })
</code></pre>
</li>
<li>
<p><strong>playAudioWhenScreenIsLocked</strong>: Pass in this option to the <code>play</code>
method to specify whether you want to allow playback when the screen
is locked.  If set to <code>true</code> (the default value), the state of the
hardware mute button is ignored, e.g.:</p>

<pre class="prettyprint"><code>var myMedia = new <a href="cordova_media_media.md.html#Media">Media</a>("http://audio.ibeat.org/content/p1rj1s/p1rj1s_-_rockGuitar.mp3")
myMedia.play({ playAudioWhenScreenIsLocked : false })
</code></pre>
</li>
<li>
<p><strong>order of file search</strong>: When only a file name or simple path is
provided, iOS searches in the <code>www</code> directory for the file, then in
the application's <code>documents/tmp</code> directory:</p>

<pre class="prettyprint"><code>var myMedia = new <a href="cordova_media_media.md.html#Media">Media</a>("audio/beer.mp3")
myMedia.play()  // first looks for file in www/audio/beer.mp3 then in &lt;application&gt;/documents/tmp/audio/beer.mp3
</code></pre>
</li>
</ul>

<hr>

<h1><a name="media.release">media.release</a></h1>

<p>Releases the underlying operating system's audio resources.
This is particularly important for Android, since there are a finite amount of
OpenCore instances for media playback. Applications should call the <code>release</code>
function for any <code><a href="cordova_media_media.md.html#Media">Media</a></code> resource that is no longer needed.</p>

<pre class="prettyprint"><code><a href="cordova_media_media.md.html#media.release">media.release</a>();
</code></pre>

<h2><a name="media.release_quick_example">Quick Example</a></h2>

<pre class="prettyprint"><code>// Audio player
//
var my_media = new <a href="cordova_media_media.md.html#Media">Media</a>(src, onSuccess, onError);

my_media.play();
my_media.stop();
my_media.release();
</code></pre>

<hr>

<h1><a name="media.seekTo">media.seekTo</a></h1>

<p>Sets the current position within an audio file.</p>

<pre class="prettyprint"><code><a href="cordova_media_media.md.html#media.seekTo">media.seekTo</a>(milliseconds);
</code></pre>

<h2><a name="media.seekTo_parameters">Parameters</a></h2>

<ul>
<li>
<strong>milliseconds</strong>: The position to set the playback position within the audio, in milliseconds.</li>
</ul>

<h2><a name="media.seekTo_quick_example">Quick Example</a></h2>

<pre class="prettyprint"><code>// Audio player
//
var my_media = new <a href="cordova_media_media.md.html#Media">Media</a>(src, onSuccess, onError);
    my_media.play();
// SeekTo to 10 seconds after 5 seconds
setTimeout(function() {
    my_media.seekTo(10000);
}, 5000);
</code></pre>

<hr>

<h1><a name="media.startRecord">media.startRecord</a></h1>

<p>Starts recording an audio file.</p>

<pre class="prettyprint"><code><a href="cordova_media_media.md.html#media.startRecord">media.startRecord</a>();
</code></pre>

<h2><a name="media.startRecord_supported_platforms">Supported Platforms</a></h2>

<ul>
<li>Android</li>
<li>iOS</li>
</ul>

<h2><a name="media.startRecord_quick_example">Quick Example</a></h2>

<pre class="prettyprint"><code>// Record audio
//
function recordAudio() {
    var src = "myrecording.mp3";
    var mediaRec = new <a href="cordova_media_media.md.html#Media">Media</a>(src,
        // success callback
        function() {
            console.log("recordAudio():Audio Success");
        },

        // error callback
        function(err) {
            console.log("recordAudio():Audio Error: "+ err.code);
        });

    // Record audio
    mediaRec.startRecord();
}
</code></pre>

<h2><a name="media.startRecord_android_quirks">Android Quirks</a></h2>

<ul>
<li>Android devices record audio in Adaptive Multi-Rate format. The specified file should end with a <em>.amr</em> extension.</li>
</ul>

<h2><a name="media.startRecord_ios_quirks">iOS Quirks</a></h2>

<ul>
<li><p>iOS only records to files of type <em>.wav</em> and returns an error if the file name extension is not correct.</p></li>
<li><p>If a full path is not provided, the recording is placed in the application's <code>documents/tmp</code> directory. This can be accessed via the <code><a href="cordova_file_file.md.html#File">File</a></code> API using <code><a href="cordova_file_localfilesystem_localfilesystem.md.html#LocalFileSystem">LocalFileSystem</a>.TEMPORARY</code>. Any subdirectory specified at record time must already exist.</p></li>
<li>
<p>Files can be recorded and played back using the documents URI:</p>

<pre class="prettyprint"><code>var myMedia = new <a href="cordova_media_media.md.html#Media">Media</a>("documents://beer.mp3")
</code></pre>
</li>
</ul>

<hr>

<h1><a name="media.stop">media.stop</a></h1>

<p>Stops playing an audio file.</p>

<pre class="prettyprint"><code><a href="cordova_media_media.md.html#media.stop">media.stop</a>();
</code></pre>

<h2><a name="media.stop_quick_example">Quick Example</a></h2>

<pre class="prettyprint"><code>// Play audio
//
function playAudio(url) {
    // Play the audio file at url
    var my_media = new <a href="cordova_media_media.md.html#Media">Media</a>(url,
        // success callback
        function() {
            console.log("playAudio():Audio Success");
        },
        // error callback
        function(err) {
            console.log("playAudio():Audio Error: "+err);
        }
    );

    // Play audio
    my_media.play();

    // Pause after 10 seconds
    setTimeout(function() {
        my_media.stop();
    }, 10000);
}
</code></pre>

<hr>

<h1><a name="media.stopRecord">media.stopRecord</a></h1>

<p>Stops recording an audio file.</p>

<pre class="prettyprint"><code><a href="cordova_media_media.md.html#media.stopRecord">media.stopRecord</a>();
</code></pre>

<h2><a name="media.stopRecord_supported_platforms">Supported Platforms</a></h2>

<ul>
<li>Android</li>
<li>iOS</li>
</ul>

<h2><a name="media.stopRecord_quick_example">Quick Example</a></h2>

<pre class="prettyprint"><code>// Record audio
//
function recordAudio() {
    var src = "myrecording.mp3";
    var mediaRec = new <a href="cordova_media_media.md.html#Media">Media</a>(src,
        // success callback
        function() {
            console.log("recordAudio():Audio Success");
        },

        // error callback
        function(err) {
            console.log("recordAudio():Audio Error: "+ err.code);
        }
    );

    // Record audio
    mediaRec.startRecord();

    // Stop recording after 10 seconds
    setTimeout(function() {
        mediaRec.stopRecord();
    }, 10000);
}
</code></pre>

<hr>

<h1><a name="MediaError">MediaError</a></h1>

<p>A <code><a href="cordova_media_media.md.html#MediaError">MediaError</a></code> object is returned to the <code>mediaError</code> callback
function when an error occurs.</p>

<h2><a name="MediaError_properties">Properties</a></h2>

<ul>
<li><p><strong>code</strong>: One of the predefined error codes listed below.</p></li>
<li><p><strong>message</strong>: An error message describing the details of the error.</p></li>
</ul>

<h2><a name="MediaError_constants">Constants</a></h2>

<ul>
<li><code><a href="cordova_media_media.md.html#MediaError">MediaError</a>.MEDIA_ERR_ABORTED</code></li>
<li><code><a href="cordova_media_media.md.html#MediaError">MediaError</a>.MEDIA_ERR_NETWORK</code></li>
<li><code><a href="cordova_media_media.md.html#MediaError">MediaError</a>.MEDIA_ERR_DECODE</code></li>
<li><code><a href="cordova_media_media.md.html#MediaError">MediaError</a>.MEDIA_ERR_NONE_SUPPORTED</code></li>
</ul>

              </div>
          </div>

        </div>

        <!-- Functionality and Syntax Highlighting -->
        <script type="text/javascript" src="index.js"></script>
        <script type="text/javascript" src="prettify/prettify.js"></script>
    </body>
</html>
