Android的 - 果冻豆 - YouTube上播放视频只有一次 [英] Android - Jelly Bean - YouTube play video only once
问题描述
我为了我的Android应用来播放YouTube vidoes正在使用的WebView。
它工作得很好,但我似乎有果冻豆的一个问题(也许以后的版本,我还不知道)。
我第一次打它工作正常的视频,但是当我尝试再次发挥它,甚至另一个视频,关闭的WebView并重新打开后,,我看到在视频加载,但然后进入暂停模式(如可在图像attched看到)。
在关闭的WebView我使用这个code,我认为这是问题的原因:
的Class.forName(android.webkit.WebView)。实现getMethod(的onPause(类[])NULL).invoke(web视图,(对象[])NULL) ;
是不是有人遇到这样的问题?
左图 - 该视频正常播放
中东形象 - 试图再次装入
右键图片 - 视频暂停,永不开始
。
这是code我使用的是:
私人无效使用loadURL()
{
progress.setVisibility(View.VISIBLE);
webview.setWebChromeClient(新WebChromeClient()); 如果(Build.VERSION.SDK_INT&下; 8){
webview.getSettings()setPluginsEnabled(真)。
}其他{
。webview.getSettings()setPluginState(PluginState.ON);
} WebSettings webSettings = webview.getSettings();
webSettings.setJavaScriptEnabled(真);
webview.setWebViewClient(新WebViewClient(){
@覆盖
公共布尔shouldOverrideUrlLoading(的WebView wView,字符串URL)
{
progress.setVisibility(View.VISIBLE);
webview.loadUrl(URL);
isLoading = TRUE;
返回true;
} @覆盖
公共无效onPageStarted(的WebView视图,字符串URL,android.graphics.Bitmap图标)
{
progress.setVisibility(View.VISIBLE);
} @覆盖
公共无效onReceivedError(的WebView观点,诠释错误code,描述字符串,字符串failingUrl)
{
progress.setVisibility(View.GONE);
isLoading = FALSE;
} @覆盖
公共无效onPageFinished(的WebView视图,字符串URL)
{
progress.setVisibility(View.GONE);
isLoading = FALSE;
}
}); webview.loadUrl(URL);
}
我通过清除/破坏的WebView解决了这个问题:
如果(的WebView!= NULL)
{
如果(isLoading)
{
webview.stopLoading();
} webview.clearCache(真);
webview.clearView();
webview.freeMemory();
webview.destroy();
}
I am using a WebView in order to play YouTube vidoes in my Android app. It worked fine, but I seem to have a problem with Jelly Bean (and maybe later versions, I don't know yet).
The first time I play a video it works fine, but when I try to play it again or even another video, after closing the WebView and re-open it, I see the video loading but then enters into pause mode (as can be seen in the image attched).
When closing the WebView I'm using this code, which I think is the cause of the problem:
Class.forName("android.webkit.WebView").getMethod("onPause", (Class[]) null).invoke(webview, (Object[]) null);
Did someone encounter this problem?
Left image - the video is played normally.
Middle image - trying to load it again.
Right image - video is paused and never started.
This is the code I'm using:
private void loadUrl()
{
progress.setVisibility(View.VISIBLE);
webview.setWebChromeClient(new WebChromeClient());
if (Build.VERSION.SDK_INT < 8) {
webview.getSettings().setPluginsEnabled(true);
} else {
webview.getSettings().setPluginState(PluginState.ON);
}
WebSettings webSettings = webview.getSettings();
webSettings.setJavaScriptEnabled(true);
webview.setWebViewClient(new WebViewClient(){
@Override
public boolean shouldOverrideUrlLoading(WebView wView, String url)
{
progress.setVisibility(View.VISIBLE);
webview.loadUrl(url);
isLoading = true;
return true;
}
@Override
public void onPageStarted (WebView view, String url, android.graphics.Bitmap favicon)
{
progress.setVisibility(View.VISIBLE);
}
@Override
public void onReceivedError (WebView view, int errorCode, String description, String failingUrl)
{
progress.setVisibility(View.GONE);
isLoading = false;
}
@Override
public void onPageFinished (WebView view, String url)
{
progress.setVisibility(View.GONE);
isLoading = false;
}
});
webview.loadUrl(url);
}
I solved the problem by clearing/destroying the webview:
if (webview != null)
{
if (isLoading)
{
webview.stopLoading();
}
webview.clearCache(true);
webview.clearView();
webview.freeMemory();
webview.destroy();
}
这篇关于Android的 - 果冻豆 - YouTube上播放视频只有一次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!