0

我想知道为什么在我将操作系统版本从 2.3.6 更新到 4.0.3 后我不能在我的 WebView 中播放 youtube.com,下面是我的代码

布局

<WebView 
    android:id="@+id/video"
    android:layout_width="fill_parent"
    android:layout_height="0dip"
    android:layout_weight="0.55"
    android:scrollbars="none"
/>

显现

在这里我想添加 "android:hardwareAccelerated="true" 但不允许在 eclip 中添加这一行:(

<application
    android:icon="@drawable/ic_perry"
    android:label="@string/app_name"
    android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" >
    <activity
        android:name=".MeasSokSopheaActivity"
        android:label="@string/app_name"
        android:screenOrientation="nosensor" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name=".video" />
</application>

活动

public class video extends Activity {
private WebView mWebView;
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.video);
    if(!haveNetworkConnection())
    {
        AlertDialog alertDialog = new AlertDialog.Builder(video.this).create();
        alertDialog.setTitle("Connection Error!");
        alertDialog.setMessage("Please connected to the internet in order to use this apps.");
        alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
              public void onClick(DialogInterface dialog, int which) {

               //here you can add functions

            } });
        alertDialog.setIcon(android.R.drawable.ic_dialog_info);
        alertDialog.show();
    }
    else
    {      
    mWebView = new WebView(this);

    mWebView = (WebView) findViewById(R.id.video);
    mWebView.setWebViewClient(new myWebClient());
    mWebView.getSettings().setJavaScriptEnabled(true);
    mWebView.getSettings().setAllowFileAccess(true);
    mWebView.getSettings().setPluginsEnabled(true);
    mWebView.getSettings().setBuiltInZoomControls(true);
    mWebView.loadUrl("http://domain/videoyoutube.php");
}
}
public class myWebClient extends WebViewClient  
{  
    @Override  
    public void onPageStarted(WebView view, String url, Bitmap favicon) {  
        // TODO Auto-generated method stub  
        super.onPageStarted(view, url, favicon);  
    }  
    @Override  
    public boolean shouldOverrideUrlLoading(WebView view, String url) {  
        // TODO Auto-generated method stub  
        view.loadUrl(url);  
        return true;
    }  
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if ((keyCode == KeyEvent.KEYCODE_BACK) && mWebView.canGoBack()) {
        mWebView.goBack();
        return true;
    }
    return super.onKeyDown(keyCode, event);
 }
@Override
public void onDestroy()
{
    if(mWebView != null)
    {
        mWebView.destroy();
        mWebView = null;
    }
    super.onDestroy();
}
private boolean haveNetworkConnection() {
    boolean haveConnectedWifi = false;
    boolean haveConnectedMobile = false;

    ConnectivityManager cm = (ConnectivityManager)  getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo[] netInfo = cm.getAllNetworkInfo();
    for (NetworkInfo ni : netInfo) {
        if (ni.getTypeName().equalsIgnoreCase("WIFI"))
            if (ni.isConnected())
                haveConnectedWifi = true;
        if (ni.getTypeName().equalsIgnoreCase("MOBILE"))
            if (ni.isConnected())
                haveConnectedMobile = true;
    }
    return haveConnectedWifi || haveConnectedMobile;
}
}
4

1 回答 1

0

YouTube 视频播放器使用 Flash,并非所有设备都支持(当然模拟器也不支持)。因此,您的视频将无法加载。

备择方案:

  • 尝试查找视频的详细信息,并创建一个Intent处理视频的新内容(ACTION_VIEW我认为使用 ?)。一些关于这样做的细节(以及它的问题)here
  • 将视频的 HTML 替换为使用 HTML5<video ...>标记的内容,该标记应在WebView. (这里有一些有限的信息)。
于 2012-06-26T01:02:34.163 回答