0
votes

I am implementing background sound in phonegap android by using Media player api. It works for one or two iteration after it does not play. It throws errors like

03-15 15:20:40.838: E/MediaPlayer(6574): Error (1,-2147483648) this error comes starting only and it plays for sometime and again stops below is the logcat errors 03-15 15:23:12.568: E/MediaPlayer(6574): error (-19, 0) 03-15 15:23:12.568: E/MediaPlayer(6574): Attempt to call getDuration without a valid mediaplayer 03-15 15:23:12.568: E/MediaPlayer(6574): error (-38, 0)

Here is the my code pauseSound = setInterval(function() { playAudio("/android_asset/www/sounds/nyan.wav"); }, 1000);

   var my_media = null;
   var mediaTimer = null;

  function playAudio(url) {
  // Play the audio file at url
    my_media = new Media(url,function() {
    // success callback
     my_media.release();     
  });

   // Play audio
   my_media.play();

}
1

1 Answers

0
votes

html code :

<audio controls id="myPlayer" style="display:none;">
  <source id="myPlayerSource" src="#" type="audio/mpeg">
Your browser does not support the audio element.
</audio>

javascript - jquery code :

function playAudio(url){
    $("#myPlayerSource").attr("src",url);
    document.getElementById('myPlayer').play()
}

check this tag in html5 HTML5 Audio