Android programming enables WebView to support HTML5 video full screen playback

This article describes the solution of Android programming to enable WebView to support HTML5 video full screen playback. Share with you for your reference, as follows:

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 don't need a view, you can declare not to use acceleration, but you need to do it in the code, as follows:

a. If you want to declare that the whole application should be accelerated:

c. If both application and activity declare hardware acceleration, but for some reasons (such as power saving?), some views do not need hardware acceleration,

Generally speaking, after the above operations are done, you can use the video tag to play the video screen. If you want to support full screen, you need to do some operations:

1) Give WebView a webchromeclient object. This webchromeclient object needs to implement onshowcustomview and onhidescustomview methods. The following is an implementation example:

Well, this writing method is different from many online writing methods. Most online examples are onshowcustomview. 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 also a private subclass, which can not be accessed outside, There is also no html5videofullscreen class in android.jar. If you want to access this class in the application, you need to add the package < Android SDK Path > / platforms / < Android version > / data / layoutlib.jar to the buildpath, and only after android-14, that is, Android 4.0, that is, the method mentioned on the Internet can be used in the era of Android 3.0, but not after Android 4.0, I use Android 4.0.3.

In fact, regardless of the version, the general meaning of this code is to put the obtained view at the top of the current activity in the onshowcustomview method, hide or delete the previous view in the onhidescustomview, put back the original overwritten WebView, and end the playback. If not, mediaplayer illegalstatus exception will be reported, and it is still a native method, There's no way to debug.

The above code is a fragment. Many friends can't solve the problem after reading it. Click here to download the complete example code.

You can download it, import the project with eclipse, and put the sample video in the root directory of sdcard, which is / MNT / sdcard from the system point of view.

The effect is shown in the figure:

Before full screen:

After full screen:

I hope this article will help you in Android programming.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>