0

i want to play mp3 file in background using jQuery in android phoneGap, i have included cordova-2.2.0.js with jquery-1.9.0.js file .. here is my html code. what i am doing wrong while i have given all permissions in Manifest File

here is my html page

<!DOCTYPE HTML>

<html>
  <head>
    <title>First App</title>
  </head>
  <body>
       <h1>Welcome to PhoneGap</h1>
       <h2>Edit assets/www/index.html</h2>
    <script src="cordova-2.2.0.js"></script>   
    <script src="jquery-1.9.0.js"></script> 
    <script>


$(document).ready(function(){
            alert("hey");
            var audio = new Audio();
            audio.src = "audio.mp3";
            audio.play();
        });

  </script>
  </body>


</html>

1 Answers1

0

try this link, use media instead of audio

var myaudio = new Media('/android_asset/www/audio/file.mp3');

for Your Error Attempt to call getDuration without valid media player

try this links

https://groups.google.com/forum/#!topic/phonegap/aa_2dHjy9C0

http://www.anddev.org/multimedia-problems-f28/mediaplayer-attempt-to-call-getduration-without-t51386.html

Android: attempt to call getduration without a valid mediaplayer

http://maffelu.net/phonegap-attempt-call-getduration-without-valid-mediaplayer/

i am saying to check this link bacause you have not posted the android code so try it.

Hope this will help.

Community
  • 1
  • 1
i.n.e.f
  • 1,773
  • 13
  • 22
  • its also not playing the audio –  Aug 30 '14 at 09:37
  • is any other permission i have to give in config.xml file –  Aug 30 '14 at 09:37
  • check the link that i have posted in my answer. – i.n.e.f Aug 30 '14 at 09:37
  • try just replacing this `var audio = new Audio();` to `var myaudio = new Media('src');` this should help. – i.n.e.f Aug 30 '14 at 09:39
  • have you checked that link & tried to replace `Media` instead of `Audio` ? – i.n.e.f Aug 30 '14 at 09:40
  • still not done.. error: Attempt to call getDuration without valid media player –  Aug 30 '14 at 09:46
  • i am running my app in emulator.. can it play audio or i have to install this app in my cellphone –  Aug 30 '14 at 09:48
  • try testing in cellphone.You might be calling getDuration before the file is fully loaded. is it ? – i.n.e.f Aug 30 '14 at 09:49
  • have you written something like this `int duration = video.getDuration();` ? & check this link `http://stackoverflow.com/questions/5710922/android-attempt-to-call-getduration-without-a-valid-mediaplayer` – i.n.e.f Aug 30 '14 at 09:52
  • no sir i just written the what i mentioned in my question –  Aug 30 '14 at 09:57
  • $(document).ready(function(){ alert("hey"); var audio = new Audio(); audio.src = "audio.mp3"; audio.play(); }); –  Aug 30 '14 at 09:57
  • can u plz help me to send me small source code playing audio in android phonegap.. please –  Aug 30 '14 at 09:58
  • sorry i can't but check my updated answer. i have posted all the links for ERROR you are getting. – i.n.e.f Aug 30 '14 at 09:59
  • bcz audio is playing correctly in my browser but its not in phonegap android –  Aug 30 '14 at 10:00
  • should i have to give any permission in any xml file file –  Aug 30 '14 at 10:13
  • yes... `` & `` in `AndroidManifest.xml` – i.n.e.f Aug 30 '14 at 10:50