The android webView cannot play a video, and cannot pause the video. If the video continues to play, the content cannot be displayed in the center of the browser.

Source: Internet
Author: User

One problem encountered this time was that webView could not play the video, and Google found that it could be set up

Setting. setPluginsEnabled (true );
This allows you to play the video, but the latest official SDK says this method has to be abandoned. We recommend that you use this method.

Setting. setPluginState (PluginState. ON );

Currently, both methods can be used. However, when the webview page is complete, you can still hear the video playing sound. so you can check the webview

The onResume method can be used to Resume playback,

OnPause can pause playback,
However, both methods are Added in API level 11, so reflection is required.
Stop playback: Use the following in the onPause method of the page:

WebView. getClass (). getMethod ("onPause"). invoke (webView, (Object []) null );

Resume playback: Use the following in the onResume method of the page:

WebView. getClass (). getMethod ("onResume"). invoke (webView, (Object []) null );

In this way, you can control the pause and resume of the video.

Another point:

WebView. resumeTimers ()

WebView. pauseTimers ();

There is a delay between the two methods, and after loading webview for the second time, the last video will be played again, but only the sound can be heard, so I personally feel unreliable, the browser of the system probably uses this method. After closing the browser based on the return part, you can still hear the sound.


If the content cannot be centered in the browser, you only need to set the following two familiarity:

Setting. setLoadWithOverviewMode (true );

Setting. setUseWideViewPort (true );


Continue study:

The same Code, tested on the android + device, found that the video still cannot be played, so the following solution is added:

1. Add:

Android: hardwareAccelerated = "true"


2. This code must be added. I don't fully understand why, but I can play it with this code.

WebView. setWebChromeClient (new WebChromeClient ());

These two steps can be played. Some people say that the android: hardwareAccelerated = "true" should be added in the application configuration. At the beginning, I also added it, however, I later found that the flash can be played with this feature.

But now the trouble is that the video cannot be played in full screen mode. After you click the full screen button and click the play and pause button again, the video will not respond and cannot be played again.

The following solutions are available on the Internet:
Http://www.techfreestyle.com/fixed-android-4-0-full-screen-flash-problem-in-webview this method has been tested and cannot solve the problem.

Https://github.com/android/platform_packages_apps_browser/blob/master/src/com/android/browser/BaseUi.java this looks like source code, because the code is too much, so there is no research.

When Daniel passes by, let's talk about how you solve the problem of full screen, thanks.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.