在安卓webview下
html5 的 video 設置autoplay 屬性
或在document ready中使用play方法
都不能使它自動播放
只能用webview的onPageFinished方法來解決此問題,代碼如下:
復制代碼 代碼如下:
mPlayer.setWebViewClient(new WebViewClient() {
// autoplay when finished loading via javascript injection
public void onPageFinished(WebView view, String url) { mPlayer.loadUrl("javascript:(function() { var videos = document.getElementsByTagName('video'); for(var i=0;i<videos.length;i++){videos[i].play();}})()"); }
});
將上面的代碼放到//here的地方即能解決問題。
復制代碼 代碼如下:
public class PlayerActivity extends Activity {
protected void onCreate(Bundle savedInstanceState) {
//here
}
}