1

In android webview, I have set web chrome client and have enabled hardware acceleration. In my webpage, I have a html5 video (inline). When a video is playing and the home button is pressed, the video does not pause leaving the user with bad user experience. How do I pause all playing videos on a webview instance without destroying it?

P.S. Please don't post JS solutions as I cannot have access to JS layer (and iframes which have videos too)

Akshaya Shanbhogue
  • 1,438
  • 1
  • 13
  • 25
  • implement onPause(){} meathod in that give stop the video – R KiranKumar Apr 02 '13 at 13:44
  • Perhaps the answer to the post "How to stop youtube video playing in Android webview?" would help? [link](http://stackoverflow.com/questions/5946698/how-to-stop-youtube-video-playing-in-android-webview) – anabonne Jul 09 '13 at 22:30

4 Answers4

2

Use this code

@Override
public void onShowCustomView(View view, CustomViewCallback callback) {
    super.onShowCustomView(view, callback);
    if (view instanceof FrameLayout){
        FrameLayout frame = (FrameLayout) view;
        if (frame.getFocusedChild() instanceof VideoView){
            VideoView video = (VideoView) frame.getFocusedChild();
            frame.removeView(video);
            a.setContentView(video);
            video.setOnCompletionListener(this);
            video.setOnErrorListener(this);
            video.start();
        }`enter code here`
    }
}
sreejithmohanan
  • 372
  • 3
  • 9
1

By default, a WebView provides no browser-like widgets, does not enable JavaScript and web page errors are ignored. If your goal is only to display some HTML as a part of your UI, this is probably fine; the user won't need to interact with the web page beyond reading it, and the web page won't need to interact with the user. If you actually want a full-blown web browser, then you probably want to invoke the Browser application with a URL Intent rather than show it with a WebView

http://developer.android.com/reference/android/webkit/WebView.html

totalmoksh
  • 19
  • 4
0

You may try intercept video streaming and show it using media player class. After that you will may access to streaming.

QArea
  • 4,955
  • 1
  • 12
  • 22
  • Could you let me know how exactly can I intercept video stream on a webview? None of the following callback seem to work : DownloadListener.onDownloadStart, WebViewClient.onLoadResource, WebChromeClient.onProgressChanged . – Akshaya Shanbhogue Apr 03 '13 at 05:41
  • Have you access to URL of video stream? If you have then you can write you own downloader and show it yourself widget – QArea Apr 03 '13 at 15:00
  • Unfortunately I wan't it to be generic. Thanks anyway :) – Akshaya Shanbhogue Apr 05 '13 at 08:52
0

I had this problem and now I have a simple, definitive answer. This assumes that your webview object is a field (member, attribute, etc) in an activity or activity fragment.

  • In the activity's onPause(), call webview.onPause();
  • In the activity's onResume(), call webview.onResume();

The onPause() bit I got elsewhere on stackoverflow. The onResume is needed to re-establish the webview's reference to the video object. If you didn't do this, if you were to play the video again on foregrounding the app, you'll end up with the same problem.

Myles Bennett
  • 533
  • 4
  • 12