最近几天,YouTube嵌入API出现了问题.问题是,当您使用官方API嵌入视频时,它只是不允许您访问API.当您尝试访问API时,您在日志(IOS)上收到错误消息,如果您尝试通过API播放视频,则视频会消失.如果您通过API加载它,但不使用API,则用户可以通过点击播放视频.
该问题在以下浏览器中仍然存在:
iPad和iPhone上的IOS 7 Safari IOS 7 iPad和iPhone上的Chrome Android 4 Chrome
(我的播放按钮使用API播放视频并产生错误)JSfiddle:http://jsfiddle.net/frdd8nvr/6/
错误信息:
Unable to post message to https://www.youtube.com. Recipient has origin http://fiddle.jshell.net.
postMessage[native code]:0
Jwww-widgetapi.js:26:357
Nwww-widgetapi.js:25
(anonymous function)[native code]:0
html5player.js:1201:97
Blocked a frame with origin "https://www.youtube.com" from accessing a frame with origin "http://jsfiddle.net". The frame requesting access has a protocol of "https", the frame being accessed has a protocol of "http". Protocols must match.
Run Code Online (Sandbox Code Playgroud)
一些调试信息:
我看到API在网站上创建iframe.src有时是http,有时是https.
我的测试表明,大多数时候YouTube服务器只是LOCATION:https:// ...对https网址的请求,但大约10%他们用适当的内容提供了http请求.
我想某个问题与强制https有关,但我无法弄清楚解决方案.你有相同的经历吗?你有解决这个问题的方法吗?这是YouTube的错误吗?
我的测试代码:
<div id="myvideo"></div>
<button id="play-button">Play</button>
Run Code Online (Sandbox Code Playgroud)
JS: …
我无法自动播放我的视频,请提供帮助。我的SDK版本
android:minSdkVersion="14"
android:targetSdkVersion="19" />
Run Code Online (Sandbox Code Playgroud)
我试图将Java脚本放入代码中指定的位置:
public void onPageFinished(WebView view, String url) { webView.loadUrl("javascript:(function() { document.getElementsByTagName('video')[0].play(); })()"); }
});
Run Code Online (Sandbox Code Playgroud)
我也尝试在URL中附加自动播放功能,但不起作用
//webView.loadUrl("http://youtube.com/embed/oY2OxMpCUVY?autoplay=1");
我的网络设置
customViewContainer = (FrameLayout)rootView.findViewById(R.id.customViewContainer);
webView = (WebView) rootView.findViewById(R.id.HelpView_Video);
final GlobleClass globalVariable = (GlobleClass) GlobleClass.getContext();
mWebViewClient = new HelpWebViewClient();
webView.setWebViewClient(mWebViewClient);
mWebChromeClient = new myWebChromeClient();
webView.setWebChromeClient(mWebChromeClient);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setPluginState(PluginState.ON);
webView.setWebViewClient(new WebViewClient() {
// autoplay when finished loading via javascript injection
public void onPageFinished(WebView view, String url) { webView.loadUrl("javascript:(function() { document.getElementsByTagName('video')[0].play(); })()"); }
});
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
// webView.getSettings().setMediaPlaybackRequiresUserGesture(false);
// } …Run Code Online (Sandbox Code Playgroud)