0

i'm trying to open this link http://www.broken-links.com/tests/video/ from webview but had no luck at all. actually it works with web browser on my phone (android 2.3), the video can be played. but it doesn't work if i tried it on my test app using webview, the website is loaded but the video is unavailable.

it's not that the webview doesn't support video tag, because the web browser can work perfectly, but i don't know where i went wrong.

please kindly help. thank you!

my simple code is

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);
}
}

and the manifest

<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>

and the layout

<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>
CloudyMarble
  • 36,908
  • 70
  • 97
  • 130
mihn
  • 41
  • 7

1 Answers1

0

Add this line in your manifest file

  android:hardwareAccelerated="true"

EDIT: This one works for me

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

you can refer this: https://stackoverflow.com/a/17273141/2210514

Community
  • 1
  • 1
Dhananjay C
  • 597
  • 9
  • 34