android webview 播放声音,如何在Android的WebView上播放音频?
这可以通过Javascript接口完成创建一个类WebInterfacepublic class WebInterface{Context mContext;WebInterface(Context c) {mContext = c;}@JavascriptInterfacepublic void playSound(String toast) {Toast.makeText(mContext,
这可以通过Javascript接口完成
创建一个类WebInterface
public class WebInterface{
Context mContext;
WebInterface(Context c) {
mContext = c;
}
@JavascriptInterface
public void playSound(String toast) {
Toast.makeText(mContext, toast, Toast.LENGTH_SHORT).show();
}
@JavascriptInterface
public void pauseSound(String toast) {
Toast.makeText(mContext, toast, Toast.LENGTH_SHORT).show();
}
}
在您的WebView类中
WebView browser;
browser=(WebView)findViewById(R.id.webkit);
browser.getSettings().setJavaScriptEnabled(true);
browser.addJavascriptInterface(new WebInterface(this), "Android");
browser.loadUrl("http://someurl.com");
在HTML代码中
function playSound(toast) {
Android.showToast(toast);
}
function pauseSound(toast) {
Android.showToast(toast);
}
更多推荐
所有评论(0)