问题描述
我正在编写音乐应用程序,并且想集成YouTube.我已经做到了,但是无法播放视频,所以我想在 WebView
上启用闪光灯,以便可以在自己的应用程序上观看YouTube上的视频.
I'm writing a music application and I want to integrate YouTube. I have done that but the videos can't be played so I want to enable flash on a WebView
so I can watch videos from YouTube on my own app.
youtube.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<WebView
android:id="@+id/webView1"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
youtube.java:
import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebView;
public class Youtube extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.youtube);
WebView wv = (WebView)findViewById(R.id.webView1);
wv.loadUrl("http://www.youtube.com");
wv.setWebViewClient(new CustomWebViewClient());
WebSettings webSettings = wv.getSettings();
wv.getSettings().setJavaScriptEnabled(true);
wv.getSettings().setPluginState(WebSettings.PluginState.ON);
}
}
CustomWebViewClient.java:
import android.webkit.WebView;
import android.webkit.WebViewClient;
class CustomWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
某些功能无法与 WebView
一起使用,因为YouTube视频无法播放.当我尝试使用 WebView
播放YouTube时,有人知道出什么问题吗?
Something is not working with the WebView
because the YouTube video does not play. Does anyone know whats wrong when I try and play YouTube with WebView
?
推荐答案
要使Flash Player在WebView中工作,您需要在androidmanifest.xml中启用硬件加速.
To make Flash Player work in a WebView you need to enable hardware acceleration in your androidmanifest.xml.
<application android:hardwareAccelerated="true" ...>
您还可以通过使用
mWebView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
这篇关于启用Flash到webview android应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!