自动播放<iframe> You Tube视频 - ?autoplay = 1无效</iframe>

时间:2013-09-07 18:45:37

标签: html5 youtube autoplay

How can I autoplay a video using the new embed code style for Youtube?

我的代码遵循这些说明并且不起作用。我也看过YouTube的帮助,他们说同样的话 - 对我不起作用。

<html><body>
<iframe width="640" height="385" src="//www.youtube.com/embed/0319ZgKMLzw?autoplay" frameborder="0" allowfullscreen></iframe></body>
</html>

看到它不是自动播放here,代码就在firebug中。

3 个答案:

答案 0 :(得分:3)

将您的嵌入代码编辑为“?autoplay = 1”并添加“http://”。这是你的工作代码......

<iframe width="640" height="385" src="http://www.youtube.com/embed/0319ZgKMLzw?autoplay=1"> </iframe>    

答案 1 :(得分:0)

尝试在代码

上的“自动播放”后添加= 1

答案 2 :(得分:0)

试试这个。它对我有用。

private class AutoPlayVideoWebViewClient extends WebViewClient {

    @Override
    public void onPageFinished(WebView view, String url) {
        super.onPageFinished(view, url);
        // mimic onClick() event on the center of the WebView
        long delta = 100;
        long downTime = SystemClock.uptimeMillis();
        float x = view.getLeft() + (view.getWidth()/2);
        float y = view.getTop() + (view.getHeight()/2);

        MotionEvent tapDownEvent = MotionEvent.obtain(downTime, downTime + delta, MotionEvent.ACTION_DOWN, x, y, 0);
        tapDownEvent.setSource(InputDevice.SOURCE_CLASS_POINTER);
        MotionEvent tapUpEvent = MotionEvent.obtain(downTime, downTime + delta + 2, MotionEvent.ACTION_UP, x, y, 0);
        tapUpEvent.setSource(InputDevice.SOURCE_CLASS_POINTER);

        view.dispatchTouchEvent(tapDownEvent);
        view.dispatchTouchEvent(tapUpEvent);
    }
}

某处,

myWebView.setWebViewClient(new AutoPlayVideoWebViewClient());