【发布时间】:2013-09-14 23:21:06
【问题描述】:
我正在编写一个音乐应用程序,我想集成 YouTube。我已经这样做了,但是视频无法播放,所以我想在WebView 上启用 Flash,这样我就可以在自己的应用上观看来自 YouTube 的视频了。
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;
}
}
由于无法播放 YouTube 视频,WebView 出现问题。当我尝试使用WebView 玩 YouTube 时,有人知道出了什么问题吗?
【问题讨论】:
标签: java android flash webview youtube