Html 使用 <iframe> 自动播放 You Tube 视频 - ?autoplay=1 不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18676660/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Autoplay with <iframe> You Tube video - ?autoplay=1 not working
提问by user2757556
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.
我的代码遵循了这些说明,但不起作用。我还查看了 YouTube 帮助,他们也说了同样的话——对我不起作用。
<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.
在这里看到它不是自动播放,代码在萤火虫中。
回答by Gencay Deniz
Edit your embed code to "?autoplay=1" and add "http://". Here is the working code for you...
将您的嵌入代码编辑为“?autoplay=1”并添加“http://”。这是您的工作代码...
<iframe width="640" height="385" src="http://www.youtube.com/embed/0319ZgKMLzw?autoplay=1"> </iframe>
回答by user2607179
try to add =1 after "autoplay" on your code
尝试在代码的“自动播放”之后添加 =1
回答by Dhunju_likes_to_Learn
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());