Click here to Skip to main content
15,867,895 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm new to android development and I'm trying to figure out how to load an HTML file that I have which contains a video. Everytime I run my app on my mobile it crashes.

This is my code which is found in the onCreate main class.

WebView wv = (WebView)this.findViewById(R.id.video);
         
 
         WebSettings wbset=wv.getSettings();
         wbset.setJavaScriptEnabled(true);
         wv.setWebViewClient(new WebClientClass());
         wv.loadUrl("file:///assets/video.html");


I have the video in the assets folder. This is my manifest xml class.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.video"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="16"
        android:targetSdkVersion="21" />

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".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 activity is right here.

<pre lang="text"><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.video.MainActivity" >

    <WebView
        android:id="@+id/video"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" />

</RelativeLayout>


Not really sure what is causing the app to crash. Any help would be really appreciated! :)
Posted
Comments
developerjm 29-Aug-14 9:32am    
Anyone ? :)

**Use#**

wv.loadUrl("file:///android_asset/video.html");

**Instead#**

wv.loadUrl("file:///assets/video.html");

For further detail refer :

developer.android.com/training/printing/html-docs.html
 
Share this answer
 
v4
Comments
developerjm 30-Aug-14 6:52am    
Thanks for your answer but it still won't work :[
Sandeep Londhe 30-Aug-14 7:35am    
what error you are getting just paste the logcat here
developerjm 31-Aug-14 4:11am    
I have a problem with my emulator and so I'm deploying it straight to my phone.
Figured out the problem. I needed to open a new intent and enable java.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900