【问题标题】:enable flash into a webview android app在 webview android 应用程序中启用 flash
【发布时间】: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


    【解决方案1】:

    要使 Flash Player 在 WebView 中工作,您需要在 androidmanifest.xml 中启用硬件加速。

    <application android:hardwareAccelerated="true" ...>
    

    您也可以通过使用为您的 WebView 单独启用它

    mWebView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-12
      • 2023-03-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多