2013-02-05 35 views
0

我試圖從webview中打開此鏈接http://www.broken-links.com/tests/video/,但根本沒有運氣。實際上它可以在我的手機上使用網絡瀏覽器(android 2.3),視頻可以播放。但它不起作用,如果我在我的測試應用程序上使用webview來嘗試它,網站已加載但視頻不可用。視頻標籤不能在我的webview上播放

這並不是說webview不支持視頻標籤,因爲網頁瀏覽器可以很好地工作,但我不知道我錯在哪裏。

請給予幫助。謝謝!

我簡單的代碼是

public class MainActivity extends Activity { 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 

    String fileUrl="http://www.broken-links.com/tests/video/"; 

    WebView wv=(WebView)findViewById(R.id.webView1); 
    WebSettings settings=wv.getSettings(); 
    settings.setAllowFileAccess(true); 
    settings.setLoadWithOverviewMode(true); 
    settings.setUseWideViewPort(true); 
    settings.setBuiltInZoomControls(true); 
    settings.setJavaScriptEnabled(true); 
    settings.setPluginsEnabled(true); 

    wv.setWebChromeClient(new WebChromeClient(){ 
     @Override 
     public boolean onConsoleMessage(
       ConsoleMessage consoleMessage) { 
      Log.e("viewengine.createWebView()", 
        consoleMessage.toString()); 
      return true; 
     } 
    }); 

    wv.setWebViewClient(new WebViewClient(){ 
     @Override 
     public boolean shouldOverrideUrlLoading(
         WebView view,String url) { 

      return true; 
     } 
    }); 

    wv.setHorizontalScrollBarEnabled(false); 
    wv.setVerticalScrollBarEnabled(false); 

    wv.loadUrl(fileUrl); 
} 
} 

和清單

<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.nsoft.test18" 
    android:versionCode="1" 
    android:versionName="1.0" > 

    <uses-sdk 
     android:minSdkVersion="8" 
     android:targetSdkVersion="17" /> 

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 
    <uses-permission android:name="android.permission.INTERNET" /> 
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 

    <application 
     android:allowBackup="true" 
     android:icon="@drawable/ic_launcher" 
     android:label="@string/app_name" 
     android:theme="@style/AppTheme" > 
     <activity 
      android:name="com.nsoft.test18.MainActivity" 
      android:label="@string/app_name" > 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
    </application> 

</manifest> 

和佈局

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
tools:context=".MainActivity" > 

<WebView 
    android:id="@+id/webView1" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentLeft="true" /> 

</RelativeLayout> 

回答

0

加入這一行清單檔案中的

android:hardwareAccelerated="true" 

編輯:這一個對我的作品

<application android:icon="@drawable/icon" 
      android:label="@string/app_name" 
      android:hardwareAccelerated="true" 
      android:allowBackup="true" 
      android:configChanges="orientation"> 

你可以參考這個: https://stackoverflow.com/a/17273141/2210514

+0

您可能需要給予更多的解釋這一點。 – JEY

+0

@JEY,我編輯了我的答案..試試這個 –