All Projects → Rubikal → awesome-video-webview

Rubikal / awesome-video-webview

Licence: MIT License
Your awesome guide for a full screen webview video player on Android

Projects that are alternatives of or similar to awesome-video-webview

WeBer
Android x5 内核 WebView 的 Helper 完美兼容 AndroidX 和 android 库,欢迎使用~~~
Stars: ✭ 20 (+33.33%)
Mutual labels:  webview
webviewhs
🌐 A Haskell binding to the webview library created by Serge Zaitsev.
Stars: ✭ 109 (+626.67%)
Mutual labels:  webview
x5 webview flutter
一个基于腾讯x5引擎的webview flutter插件,简化集成,一行代码打开视频播放,暂时只支持android使用
Stars: ✭ 90 (+500%)
Mutual labels:  webview
react-native-react-bridge
An easy way to integrate your React (or Preact) app into React Native app with WebView.
Stars: ✭ 84 (+460%)
Mutual labels:  webview
appWeiboInfoCrawl
use webview let user to login Weibo,and the auto get user info(使用webview让用户授权登录微博,然后自动获取用户信息)
Stars: ✭ 27 (+80%)
Mutual labels:  webview
msLog
log for webView & webApp 用于webView和webApp的log工具
Stars: ✭ 25 (+66.67%)
Mutual labels:  webview
react-native-web-view
An implementation of React Native's WebView that allows for postMessage on iOS devices.
Stars: ✭ 13 (-13.33%)
Mutual labels:  webview
Journey
JCEF-powered cross-platform web browser
Stars: ✭ 85 (+466.67%)
Mutual labels:  webview
webview
Nim bindings for https://github.com/zserge/webview
Stars: ✭ 91 (+506.67%)
Mutual labels:  webview
RNApp
react native app
Stars: ✭ 43 (+186.67%)
Mutual labels:  webview
flutter-webview-windows
A WebView2-powered Flutter WebView implementation for the Windows platform.
Stars: ✭ 83 (+453.33%)
Mutual labels:  webview
animaris
Documentation and Mock for JSBridge base on ThinkJS & MongoDB & React & Antd.
Stars: ✭ 28 (+86.67%)
Mutual labels:  webview
RxWebView
RxJava2 binding APIs for Android's WebView
Stars: ✭ 22 (+46.67%)
Mutual labels:  webview
frida-uiwebview
Inspect and manipulate UIWebView-hosted GUIs through Frida.
Stars: ✭ 36 (+140%)
Mutual labels:  webview
webviewer-android
Simple WebView for Android
Stars: ✭ 15 (+0%)
Mutual labels:  webview
CefGlue
.NET binding for The Chromium Embedded Framework (CEF)
Stars: ✭ 44 (+193.33%)
Mutual labels:  webview
os-fileup
Helper app to understand how to upload files and do basic image/video processing in hybrid android apps.
Stars: ✭ 207 (+1280%)
Mutual labels:  webview
rust-webview-todomvc-yew
lightweight desktop todomvc implementation using rust,wasm and web-view
Stars: ✭ 92 (+513.33%)
Mutual labels:  webview
Android-VimeoPlayer
Unofficial Vimeo video player library for Android.
Stars: ✭ 46 (+206.67%)
Mutual labels:  webview
WebViewJavaScriptBridge
android webview javascript bridge
Stars: ✭ 24 (+60%)
Mutual labels:  webview

Your awesome recipe for video enabled webviews

This is your ultimate recipe with minimal changes into supporting full screen webview videos, that could be used anywhere in your application.

Issues this guide will help you fix

  • Enable full screen toggle in an Activity/Fragment
  • Enable full screen toggle in Recyclerview/Nested Recyclerview
  • Structure your xml views accordingly to avoid any glitches during toggling
  • Save your video state between normal and full screen views without any handling.
  • Enable download button (Soon)

Cause of the problem

According to android docs, if a simple quesiton asked, what does a webview do ? The answer would be,

All that WebView does, by default, is show a web page.

Link to webview docs: Go ahead !

Limited capabilities, very little control over the way webview work or look, requires a lot of changes in the FE side if you would like to perform a specific action, and would probably need to implement an interface to deal with some of the UI components in your view.

One of the major challenges is video handling in webviews, videos are just displayed as videos, that being said, one very big issue is full screen handling which is not enabled by default, one reason for this how the android structures UI into XMLs, and inflates those XMLs into a parent activity that holds whatever views inside, you have to tell android how to toggle and how to inflate the two modes Full screen and Normal screen.

Breaking down the solution

That being said, enough chitchat, let us dig into the actual steps taken for this fix:

  1. Locate and find the normal layout for the webview in your current view that is inflated onto your running instance.

  2. Locate and find an empty layout that you need your webview to be inflated into during Full screen mode.

  3. Implement a custom WebChromeClient, a client is the engine of a webview, WebViewClient lacks a lot of features though, only to be found in its chrome sibling, includes some powerful tools like javascript invoking, ability to override favicon and of course ability to handle custom views on full screen toggle.

  4. (Bonus tip) You have a recyclerview ? No worries, consider your parent still as your holding activity, implement an interface that deals between the viewholder and the activity to toggle full screen.

  5. Put the pieces together, and watch the magic working seamlessly.

Code snippets

1. Locating normal layout (Layout that contains normal view)

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:layout_marginBottom="@dimen/dimen_5_dp">
    
    ... LAYOUT TAGS GOES HERE

    <WebView
        android:id="@+id/chat_item_video_player"
        android:layout_width="match_parent"
        android:layout_height="@dimen/dimen_120_dp"
        android:layout_marginStart="@dimen/dimen_10_dp"
        android:layout_marginEnd="@dimen/dimen_10_dp"
        android:layout_marginTop="@dimen/dimen_5_dp"
        android:background="@drawable/shape_rect_rounded_gray_background" />
        
    ... OTHER LAYOUT TAGS GOES HERE
    
</LinearLayout>

2. Create an empty view, matching layout params with parent layout.

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/cl_parent"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/white"
    tools:context=".ui.fragments.ChatActivity"> <-- THIS IS YOUR PARENT/HOLDING LAYOUT

    ... LAYOUT TAGS GOES HERE

    <FrameLayout
        android:id="@+id/fl_full_video_player"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/black"
        android:visibility="gone" />
        
    ... OTHER LAYOUT TAGS GOES HERE

</android.support.constraint.ConstraintLayout>

3. Create an interface that communicates with the holding activity

private interface OnFullScreenToggleListener {
    fun onShowFullScreen(view: View)
    fun onHideFullScreen(view: View)
}

4. Create a custom web chrome client that overrides the custom view handling

Hint: Create a private custom view reference to pass it on hide custom view callback, and initialize the mFullScreenListener upon creating the child view

private class CustomWebClient : WebChromeClient() {
    override fun onShowCustomView(view: View, callback: WebChromeClient.CustomViewCallback) {
        mFullScreenListener.onShowFullScreen(view)
        mCustomView = view
    }

    override fun onHideCustomView() {
        if (mCustomView == null)
            return

        mFullScreenListener.onHideFullScreen(mCustomView)
        mCustomView = null
    }
}

5. Initialize the webview with the custom web client

chat_item_video_player.setWebChromeClient(CustomWebClient())

6. Implement the interface in your target activity/fragment

override fun onShowFullScreen(view: View) {
    fl_full_video_player.addView(view)
    fl_full_video_player.setVisibility(View.VISIBLE)
}

override fun onHideFullScreen(view: View) {
    fl_full_video_player.removeView(view)
    fl_full_video_player.setVisibility(View.GONE)
}

7. Build, run and enjoy !

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].