title: Playing audio via phonegap and cordova for Android
body: <p>I've been messing around with programming a test app for android and I've come across a issue playing a audio file. My problem lies with as soon as the page loads the audio file plays when it's not meant to and doesn't play via a button click</p>
  
  <p>I'm using the example for cordova to get the audio to play but I can't work out why the audio plays straight away</p>
  
  <p>Thanks </p>
  
  <p>Script</p>
  
  <pre><code>script type="text/javascript" charset="utf-8" src="cordova-2.2.0.js"&gt;&lt;/script&gt;
          &lt;script type="text/javascript" charset="utf-8"&gt;
  
          // Wait for Cordova to load
          //
          document.addEventListener("deviceready", onDeviceReady, false);
  
          // Cordova is ready
          //
          function onDeviceReady() {
              playAudio("/android_asset/www/audio/audio.mp3");
          }
  
          // Audio player
          //
          var my_media = null;
          var mediaTimer = null;
      function playAudio(src) {
              if (my_media == null) {
                  // Create Media object from src
                  my_media = new Media(src, onSuccess, onError);
              } // else play current audio
              // Play audio
              my_media.play();
  
              // Update my_media position every second
              if (mediaTimer == null) {
                  mediaTimer = setInterval(function() {
                      // get my_media position
                      my_media.getCurrentPosition(
                          // success callback
                          function(position) {
                              if (position &gt; -1) {
                                  setAudioPosition((position) + " sec");
                              }
                          },
                          // error callback
                          function(e) {
                              console.log("Error getting pos=" + e);
                              setAudioPosition("Error: " + e);
                          }
                      );
                  }, 1000);
              }
          }
  
  &lt;/script&gt;
  </code></pre>
  
  <p>HTML button click </p>
  
  <pre><code>&lt;a class="button" onclick="playaudio('/android_asset/www/audio/audio.mp3')";&gt;Play that audio!&lt;/a&gt;
  </code></pre>