我正在尝试在Android WebView中使用youtube iframe播放器,但在5.x上它在5.x上失败,一切都很好.
当我在4.x中尝试时,播放器加载视频,当我开始播放时,我只看到视频声音.
logcat反复填充chrome错误消息:
当我在4.x中尝试时,播放器加载视频,当我开始播放时,我只看到视频声音.
logcat反复填充chrome错误消息:
E/chromium(20362): [ERROR:gles2_cmd_decoder.cc(5942)] [.Compositor-Onscreen-0x5db83bb8]GL ERROR :GL_INVALID_OPERATION : glUseProgram: program not linked E/chromium(20362): [ERROR:gles2_cmd_decoder.cc(5718)] [.Compositor-Onscreen-0x5db83bb8]GL ERROR :GL_INVALID_OPERATION : glUniformMatrix4fv: wrong uniform function for type E/chromium(20362): [ERROR:gles2_cmd_decoder.cc(5718)] [.Compositor-Onscreen-0x5db83bb8]GL ERROR :GL_INVALID_OPERATION : glUniform1iv: wrong uniform function for type
以下是我设置WebView的方法:
this.webview = (WebView) this.findViewById(R.id.webview); WebSettings settings = this.webview.getSettings(); settings.setJavaScriptEnabled(true); settings.setAppCacheEnabled(false); this.webview.setWebChromeClient(new WebChromeClient()); ... this.webview.loadUrl(ADDRESS_OF_PAGE);
另外,我在清单中启用了硬件加速:
<application ... android:hardwareAccelerated="true">
这是js部分:
var player; var VIDEO_ID = "EIsauUFIguE"; window.onYouTubeIframeAPIReady = function() { console.log("youtube api ready,loading player"); player = new YT.Player("playerIframe",{ width: "100%",height: "100%",videoId: null,events: { onReady: onPlayerReady,onStateChange: onPlayerStateChange,onPlaybackQualityChange: onPlayerPlaybackQualityChange,onError: onPlayerError },playerVars: { modestbranding: 1,playsinline: 1,fs: 0,showinfo: 0 } }); } function onPlayerReady(event) { console.log("player is ready: ",event); playVideo(); } function onPlayerStateChange(event) { console.log("player state change: ",event); } function onPlayerPlaybackQualityChange(event) { console.log("player playback quality change: ",event); } function onPlayerError(event) { console.log("player error: ",event); } function playVideo() { console.log("playing video: " + VIDEO_ID); player.loadVideoById(VIDEO_ID); player.setPlaybackQuality("medium"); } function loadPlayer() { console.log("loading youtube api"); var tag = document.createElement("script"); tag.src = "https://www.youtube.com/iframe_api"; var firstScriptTag = document.getElementsByTagName("script")[0]; firstScriptTag.parentNode.insertBefore(tag,firstScriptTag); } loadPlayer();
知道它为什么会这样,只在android 4.x中?
谢谢.