kulyk / react-native-android-wv-video Goto Github PK
View Code? Open in Web Editor NEWAndroid WebView component supporting playing HTML5 videos at fullscreen
Android WebView component supporting playing HTML5 videos at fullscreen
package com.akulyk.react.androidwebview;
import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.graphics.Color;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.widget.FrameLayout;
import static android.view.ViewGroup.LayoutParams;
/**
Provides support for full-screen video on Android
*/
public class VideoEnabledWebChromeClient extends WebChromeClient {
private final FrameLayout.LayoutParams FULLSCREEN_LAYOUT_PARAMS = new FrameLayout.LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, Gravity.CENTER);
private WebChromeClient.CustomViewCallback mCustomViewCallback;
private Activity mActivity;
private View mWebView;
private View mVideoView;
public VideoEnabledWebChromeClient(Activity activity, WebView webView) {
mWebView = webView;
mActivity = activity;
}
@OverRide
public void onShowCustomView(View view, CustomViewCallback callback) {
if (mVideoView != null) {
callback.onCustomViewHidden();
return;
}
// Store the view and it's callback for later, so we can dispose of them correctly
mVideoView = view;
mCustomViewCallback = callback;
view.setBackgroundColor(Color.BLACK);
getRootView().addView(view, FULLSCREEN_LAYOUT_PARAMS);
mWebView.setVisibility(View.GONE);
if(mActivity!=null){
mActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
WindowManager.LayoutParams params = mActivity.getWindow().getAttributes();
params.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
mActivity. getWindow().setAttributes(params);
mActivity. getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
}
}
@OverRide
public void onHideCustomView() {
if (mVideoView == null) {
return;
}
mVideoView.setVisibility(View.GONE);
// Remove the custom view from its container.
getRootView().removeView(mVideoView);
mVideoView = null;
mCustomViewCallback.onCustomViewHidden();
mWebView.setVisibility(View.VISIBLE);
if(mActivity!=null){
mActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
final WindowManager.LayoutParams attrs =mActivity.getWindow().getAttributes();
attrs.flags &= (~WindowManager.LayoutParams.FLAG_FULLSCREEN);
mActivity.getWindow().setAttributes(attrs);
mActivity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
}
}
private ViewGroup getRootView() {
return ((ViewGroup) mActivity.findViewById(android.R.id.content));
}
}
Hello,
I am using this package it helps with full screen video playing on android devices. There are 2 problem that I would like to ask:
Issue 1 -
My code is -
<AndroidWebView
ref="videoView"
scalesPageToFit={true}
javaScriptEnabled={true}
allowsInlineMediaPlayback={true}
//ignoreSslError={true}
source={{uri: item.node.newsUrl + '&fs=1'}}
/>
When I click on Full screen button it start video in landscape mode in full-screen. but after 1 second or 2 my screen goes blank and no turning back from there. I have to kill the app.
CSS:
newsVideo: {
overflow: 'hidden',
alignSelf: 'center',
width: deviceWidth,
height: 225,
borderRadius: 0,
marginTop: 0,
borderColor: 'transparent',
},
Please suggest a solution if you can think of any. Thanks.
Issue 2 - I would like to know if there is any way to get data when I click on this webview, basically detect the click on video.
Thanks
Hello,
Same title, how to use callback when click to fullscreen button on WebView?
[ ] - Add support for horizontal full-screen mode
Is possible to update the library to support fullscreen in the landscape mode.
Thank you for your work!
1. path error
// Current README
include ':react-native-android-wv-video'
project(':react-native-android-wv-video').projectDir = file('../node_modules/react-native-android-wv-video/android')
// Right
include ':react-native-android-wv-video'
project(':react-native-android-wv-video').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-android-wv-video/android/app')
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.