Friday 15 January 2010

html5 - Android method doesnot work at html -


I created the new Android app because it displays static information, I made The html5 and I call the html5 files on my webview one of the functions is the mp3 mp3 function when I click on the button html and android < / Strong> was in my interface but did not run MP3 .

  increases the public class WebAppInterface activity {reference mContext; / ** Instance the interface and set the reference * / WebAppInterface (reference c) {mContext = c; } Public Zero Audioplayer () {// Setup MediaPlayer MediaPlayer mp = New MediaPlayer (); {Try AssetFileDescriptor descriptor = getAssets (). OpenFd ("Azan.mp3"); Mp.setDataSource (descriptor.getFileDescriptor (), descriptor.getStartOffset (), descriptor.getLength ()); Descriptor.close (); Mp.prepare (); Mp.start (); } Hold (exception e) {e.printStackTrace (); }}   

}

  create a protected zeros (bundle saved instainstate) {super.onCreate (savedInstanceState); SetContentView (R.layout.activity); // call HTML files webview myWebView = (webview) Find VVBIID (RIDX); WebSettings webSettings = myWebView.getSettings (); WebSettings.setJavaScriptEnabled (true); MyWebView.loadUrl ("File: ///android_asset/index.html"); // start myWebView.addJavascriptInterface (New WebAppInterface (this), "Android"); }   

  & lt; Input type = "button" value = "play mp3" onClick = "playmp3 ()" /> & Lt; Script type = "text / javascript" & gt; Function playmp3 () {Android.audioPlayer (); } & Lt; / Script & gt;    

You set the Java method as the window Android.audioPlayer (); . Just add window in the beginning

No comments:

Post a Comment