Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法使用html5音频标记在android emulator中播放音频_Android_Html_Html5 Audio - Fatal编程技术网

无法使用html5音频标记在android emulator中播放音频

无法使用html5音频标记在android emulator中播放音频,android,html,html5-audio,Android,Html,Html5 Audio,我开发了一个html5页面,包含所有htmls标签。我将该文件推送到android emulator/设备中。当我尝试启动该页面时,我可以查看图像,但无法播放音频。。还有其他原因吗请尽快帮我 Im能够播放tat音频Im桌面浏览器。Android(WebKit)2.2默认浏览器在技术上支持HTML5音频,但不能播放任何使用流行编解码器编码的媒体文件。由于浏览器供应商对HTML5音频标签的实现不一致,您需要使用JavaScript来准确确定是否可以使用本机音频或回退 这只是实现在android中播放

我开发了一个html5页面,包含所有htmls标签。我将该文件推送到android emulator/设备中。当我尝试启动该页面时,我可以查看图像,但无法播放音频。。还有其他原因吗请尽快帮我


Im能够播放tat音频Im桌面浏览器。

Android(WebKit)2.2默认浏览器在技术上支持HTML5音频,但不能播放任何使用流行编解码器编码的媒体文件。由于浏览器供应商对HTML5音频标签的实现不一致,您需要使用JavaScript来准确确定是否可以使用本机音频或回退

这只是实现在android中播放html文件音频目标的另一种方式。因为android 2.2不支持HTML5的音频标签

使用Android的Mediaplayer()播放音频。您可以从您在HTML文件中编写的javascript调用android函数

这是如何从javascript代码调用java文件中编写的函数的示例 (除了ShowAndroidToast函数,您可以编写代码使用mediaplayer对象播放音频。)

WebView-WebView=(WebView)findViewById(R.id.WebView);
addJavascriptInterface(新的WebAppInterface,即“Android”);
--------------------------------
公共类WebAppInterface{
语境;
/**实例化接口并设置上下文*/
WebAppInterface(上下文c){
mContext=c;
}
/**在网页上显示祝酒词*/
@JavascriptInterface
公共空间展示土司(串土司){
Toast.makeText(mContext,Toast,Toast.LENGTH_SHORT).show();
}
}
---------------------------
java sript代码
函数showAndroidToast(toast){
showToast(toast);
}
通过这种方式,您可以从Android代码调用音频。

只需检查一下。。。。
  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>