javascript - unable to play an audio mp3 file in phonegap android -


i new phonegap (cardova),i want play local mp3 file,it can play file url,but not local file.my file located in assets --> www --> audio --> ikhlas.mp3 , using jquery mobile multiple pages. , in each page have play different audio file oclick play button. when ever click button play got following errors :

 07-19 07:43:58.829: e/mediaplayer(1081): attempt call getduration without valid mediaplayer, 07-19 07:43:58.838: e/mediaplayer(1081): attempt perform seekto in wrong state: mplayer=0x0, mcurrentstate=0 

any highly appreciated. thanks

<!doctype html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1">  <title></title>  <script type="text/javascript" charset="utf-8" src="js/cordova.js"></script> <link rel="stylesheet"  href="css/themes/default/jquery.mobile-1.3.1.min.css"> <link rel="stylesheet" href="_assets/css/jqm-demos.css"> <link rel="shortcut icon" href="favicon.ico">     <link rel="stylesheet" href="http://fonts.googleapis.com/css?family=open+sans:300,400,700"> <link rel="stylesheet" href="css/themes/default/my_style.css"> <link rel="stylesheet" media="screen" href="http://openfontlibrary.org/face/droid-arabic-naskh" rel="stylesheet" type="text/css"/> <script src="js/jquery.js"></script> <script src="_assets/js/index.js"></script> <script src="js/jquery.mobile-1.3.1.min.js"></script>   <script> var myaudio = new audio('/android_asset/www/audio/ikhlas.mp3'); function playstream() {   try {    //alert ("ffff");      myaudio.id = 'playermyadio';     myaudio.play();   } catch (e) {     alert('no audio support!');   }  }   function stopstream() {   try {    myaudio.pause();   } catch (e) {     alert('no audio support!');   }  } </script>  <div data-role="page" id="ikhlas"> <div data-role="header"> <a href="#page2" class="ui-btn-left" data-icon="back" data-iconpos="notext" class="ui-   icon-nodisc" data-iconshadow="false" data-transition="slide">back</a> <a href="index.html" data-icon="home" class="ui-btn-right" class="ui-icon-nodisc" data-iconshadow="false" data-iconpos="notext">home</a>   </div> <!-- /header --> <body> <div data-role="content"> <button onclick="playstream()">play</button><br /> <button onclick="stopstream()">stop</button><br /> </div> <!-- /content --> <div data-role="footer"><a href="#page2" data-role="button" data-icon="back"      data-transition="slide">go back</a></div> </div> </body> </html> 

use media instead of audio , put line of code

var myaudio = new media('/android_asset/www/audio/ikhlas.mp3'); 

inside function playstream()


Comments