Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: ci
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: gradle/wrapper-validation-action@v1
- run: ./gradlew build
14 changes: 9 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
/.gradle
/.idea
/build
/app/build
local.properties
*.iml
.gradle/
local.properties
.idea/
.DS_Store
build/
captures/
.externalNativeBuild/
.cxx/
1 change: 0 additions & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,3 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

21 changes: 11 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
VideoEnabledWebView
===================
# VideoEnabledWebView

Android's WebView and WebChromeClient class extensions that enable fully working, cross-device, HTML5 video support in Android 2.2 (API level 8) onwards. Actively maintained and tested up to Android 4.4 (API level 19) with its new Chromium webview.
[![ci][1]][2]

Motivation
----------
Android's WebView and WebChromeClient class extensions that enable fully working, cross-device, HTML5 video support in Android 4.0.3 (API level 15) onwards. Actively maintained and tested up to Android 10 (API level 29) with its new Chromium webview.

## Motivation

Android's default WebView doesn't work well with HTML5 videos (i.e. the _<video>_ tag). Unlike iOS's UIWebView, which is similar to a Safari tab with respect to video handling, Android's implementation is far from how a Chrome tab behaves. API level fragmentation and manufacturer customizations, which usually include video player related UI changes, only add up to the mess. Things that don't work consistently across devices include:
- Videos not even playing.
Expand All @@ -16,8 +16,7 @@ Android's default WebView doesn't work well with HTML5 videos (i.e. the _<vid

VideoEnabledWebView and VideoEnabledWebChromeClient are two handy extension classes that come to help deal with these issues. I originally wrote them for my personal use, but they got a lot of attention in [StackOverflow](http://stackoverflow.com/a/16179544/423171), and that's the reason they are now here. Contributions are appreciated.

How to use it
-------------
## How to use it

For a working example, download the whole repository and open it with __Android Studio__. Do not use the Open Project option, use __Import Project__.

Expand All @@ -27,12 +26,14 @@ VideoEnabledWebChromeClient can be used alone if you do not require the function

Finally, you need to define all the views that you will be using in your layout files, and provide the relevant references in the classes' constructors.

Common issues check-list
------------------------
## Common issues check-list

1. Remember to declare the __internet permission__ in AndroidManifest.xml if you are using the WebView to access remote content: `<uses-permission android:name="android.permission.INTERNET" />`
2. Remember to enable __hardware acceleration__ in AndroidManifest.xml for in-line videos to work in API level 11. The field will have no effect in earlier API levels: `android:hardwareAccelerated="true"`
3. Remember to __initialize the VideoEnabledWebChromeClient__ and link it with the VideoEnabledWebView. Follow the example in ExampleActivity.java.
4. Remember to override your Activity's __onBackPressed()__ and pass the event to the VideoEnabledWebChromeClient. Follow the example in ExampleActivity.java.
4. Remember to override your Activity's __onBackPressed()__ and pass the event to the VideoEnabledWebChromeClient. Follow the example in ExampleActivity.java.
5. Remember to specify and/or programmatically inflate the __videoLayout__, __nonVideoLayout__, and, optionally, __loadingView__. Follow the example in ExampleActivity.java and the xml layout files in res/layout.
6. If you are using __ProGuard__, remember to add the fully qualified name of the Javascript interface to the rules file: `-keepclassmembers class name.cpr.VideoEnabledWebView$JavascriptInterface { public *; }`

[1]: https://github.com/cprcrack/VideoEnabledWebView/workflows/ci/badge.svg
[2]: https://github.com/cprcrack/VideoEnabledWebView/actions
19 changes: 0 additions & 19 deletions VideoEnabledWebView.iml

This file was deleted.

109 changes: 0 additions & 109 deletions app/app.iml

This file was deleted.

16 changes: 9 additions & 7 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 22
buildToolsVersion '25.0.0'

compileSdkVersion 29
buildToolsVersion '29.0.2'
defaultConfig {
applicationId "cpr.name.videoenabledwebview"
minSdkVersion 8
targetSdkVersion 22
minSdkVersion 15
targetSdkVersion 29
versionCode 2
versionName "1.0.1"
}
Expand All @@ -17,9 +16,12 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
lintOptions {
warningsAsErrors true
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.0.0'
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
}
6 changes: 6 additions & 0 deletions app/lint.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<lint>
<issue id="GoogleAppIndexingWarning" severity="ignore"/>
<issue id="GradleDependency" severity="informational"/>
<issue id="OldTargetApi" severity="informational"/>
</lint>
22 changes: 13 additions & 9 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in C:\Program Files\Android Studio\sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# Add any project specific keep options here:

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
-keepclassmembers class name.cpr.VideoEnabledWebView$JavascriptInterface {
public *;
}
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
3 changes: 2 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
<uses-permission android:name="android.permission.INTERNET" />

<application
android:allowBackup="true"
android:allowBackup="false"
android:fullBackupContent="false"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme"
Expand Down
22 changes: 7 additions & 15 deletions app/src/main/java/name/cpr/ExampleActivity.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package name.cpr;

import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import androidx.appcompat.app.AppCompatActivity;
import cpr.name.videoenabledwebview.R;

public class ExampleActivity extends ActionBarActivity
public class ExampleActivity extends AppCompatActivity
{
private VideoEnabledWebView webView;
private VideoEnabledWebChromeClient webChromeClient;
Expand Down Expand Up @@ -50,33 +50,25 @@ public void toggledFullscreen(boolean fullscreen)
attrs.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
attrs.flags |= WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
getWindow().setAttributes(attrs);
if (android.os.Build.VERSION.SDK_INT >= 14)
{
//noinspection all
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);
}
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);
}
else
{
WindowManager.LayoutParams attrs = getWindow().getAttributes();
attrs.flags &= ~WindowManager.LayoutParams.FLAG_FULLSCREEN;
attrs.flags &= ~WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
getWindow().setAttributes(attrs);
if (android.os.Build.VERSION.SDK_INT >= 14)
{
//noinspection all
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
}
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
}

}
});
webView.setWebChromeClient(webChromeClient);
// Call private class InsideWebViewClient
webView.setWebViewClient(new InsideWebViewClient());

// Navigate anywhere you want, but consider that this classes have only been tested on YouTube's mobile site
webView.loadUrl("http://m.youtube.com");
webView.loadUrl("https://www.youtube.com/watch?v=HGZYtDZhOEQ");

}

Expand All @@ -89,7 +81,7 @@ public boolean shouldOverrideUrlLoading(WebView view, String url) {
return true;
}
}

@Override
public void onBackPressed()
{
Expand Down
Loading