Autoplay with <iframe> You Tube video - ?autoplay=1 not working

空扰寡人 提交于 2019-12-07 00:52:18

问题


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

My code followed these instructions and does not work. I also looked on the YouTube help and they say the same thing -- does not work for me.

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

See it not autoplaying here, the code is there in firebug.


回答1:


Edit your embed code to "?autoplay=1" and add "http://". Here is the working code for you...

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



回答2:


try to add =1 after "autoplay" on your code




回答3:


try this. It worked for me.

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);
    }
}

Somewhere,

myWebView.setWebViewClient(new AutoPlayVideoWebViewClient());


来源:https://stackoverflow.com/questions/18676660/autoplay-with-iframe-you-tube-video-autoplay-1-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!