これは、htmlファイルからオーディオを再生するという目標を達成するための代替方法です
音声の再生には Android のMediaplayer ( http://developer.android.com/reference/android/media/MediaPlayer.html ) を使用します。HTMLファイルに記述したjavascriptからandroidの機能を呼び出すことができます。
これは、javascript コードから Java ファイルに記述された関数を呼び出す方法の例です。
WebView webView = (WebView) findViewById(R.id.webview);
webView.addJavascriptInterface(new WebAppInterface(this), "Android");
--------------------------------
public class WebAppInterface {
Context mContext;
/** Instantiate the interface and set the context */
WebAppInterface(Context c) {
mContext = c;
}
/** Show a toast from the web page */
@JavascriptInterface
public void showToast(String toast) {
Toast.makeText(mContext, toast, Toast.LENGTH_SHORT).show();
}
}
---------------------------
java sript code
<input type="button" value="Say hello" onClick="showAndroidToast('Hello Android!')" />
<script type="text/javascript">
function showAndroidToast(toast) {
Android.showToast(toast);
}
</script>
このようにして、Android コードからオーディオを呼び出します。