In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces how to make WebView support HTML5 Video full-screen playback in Android. The article is very detailed and has a certain reference value. Interested friends must finish reading it!
1) you need to declare in the AndroidManifest.xml file that you need to use HardwareAccelerate, which can be refined to the Activity level. If you do not need View, you can declare that you do not use acceleration, but you need to do it in the code, as follows:
a. If you want to declare that the entire application should be accelerated:
< application ... android:hardwareAccelerated ="true">b. If you want to declare in Activity, then:
, can also be further refined to Window, getWindow.setFlags (WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED); WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED
c. If application or activity both declare hardware acceleration, but for some reason (such as saving power?) If some View do not require hardware acceleration
View.setLayerType (View.LAYER_TYPE_SOFTWARE, null)
2) it can be said that it is strange that you need to use tags in the AndroidManifest.xml file, and if it is empty, you must write targetSDK or minSDK, but I have tried it, no matter how many versions you write. In theory, Android should be able to accelerate 2D rendering from 3. 0 (API Level 11), but I set targetSDK to 5, but I have to write this label.
Generally speaking, after doing the above, you can use the video tag to play the video. If you want to support full screen, you need to do a little more:
1) give webview a WebChromeClient object, which needs to implement the onShowCustomView and onHideCustomView methods. Here is an implementation example:
@ Override public void onShowCustomView (View view, CustomViewCallback callback) {if (myCallback! = null) {myCallback.onCustomViewHidden (); myCallback = null; return } long id = Thread.currentThread (). GetId (); WrtLog. V ("WidgetChromeClient", "rong debug in showCustomView Ex:" + id); ViewGroup parent = (ViewGroup) mWebView.getParent (); String s = parent.getClass (). GetName (); WrtLog. V ("WidgetChromeClient", "rong debug Ex:" + s); parent.removeView (mWebView); parent.addView (view); myView = view; myCallback = callback; chromeClient = this;} private View myView = null; private CustomViewCallback myCallback = null Public void onHideCustomView () {long id = Thread.currentThread (). GetId (); WrtLog. V ("WidgetChromeClient", "rong debug in hideCustom Ex:" + id); if (myView! = null) {if (myCallback! = null) {myCallback.onCustomViewHidden () MyCallback = null;} ViewGroup parent = (ViewGroup) myView.getParent (); parent.removeView (myView); parent.addView (mWebView); myView = null }}
Well, this is different from many online writings, most of the examples on the Internet are that the view received by the onShowCustomView method is a VideoView object, and here is a videoSurfaceView subclass of HTML5VideoFullScreen that can not be found, and this subclass is a subclass of private, so there is no way to access it outside, and there is no HTML5VideoFullScreen class in android.jar. If you want to access this class in application, you need to add the package / platforms//data/layoutlib.jar to buildpath, and it's only done since android-14, that is, android4.0. That is to say, the method mentioned on the Internet is available in the android3.0 era, but not in android4.0. I use android4.0.3.
In fact, no matter what version it is, the general meaning of this code is: in the onShowCustomView method, put the acquired view on the top of the current Activity, in onHideCustomView, hide or delete the previous view, put the original covered webview back, and end the playback, whether it will report MediaPlayer IllegalStatusException or Native method, it is impossible to debug at all.
You can download it, import the project with eclipse, and put the sample video in the root directory of sdcard. From a system point of view, it can be / mnt/sdcard.
The effect is as shown in the figure:
Before full screen:
After full screen:
The above is all the contents of the article "how to make WebView support HTML5 Video full-screen playback in Android". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.