I am new to Phonegap (Cardova), I want to play a local mp3 file, it can play a file from url , but not a local file. My file is in Assets --> www --> audio --> Ikhlas.mp3 , I am using Jquery Mobile with several pages. and on each page I have to play a different audio file using the Oclick Play button. when I click the button to play, I got the following errors :
07-19 07:43:58.829: E/MediaPlayer(1081): Attempt to call getDuration without a valid mediaplayer, 07-19 07:43:58.838: E/MediaPlayer(1081): Attempt to perform seekTo in wrong state: mPlayer=0x0, mCurrentState=0
Any help would be greatly 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 { </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> <body> <div data-role="content"> <button onClick="playStream()">play</button><br /> <button onClick="stopStream()">stop</button><br /> </div> <div data-role="footer"><a href="#page2" data-role="button" data-icon="back" data-transition="slide">Go Back</a></div> </div> </body> </html>
source share