cavallo
cavallo

Reputation: 4414

how to play html5 video on a webview android

i am trying to load a webpage on a web view where the page has a video in it. i am able to load the web page on the web view but the video is not playing and the audio is heard. this is the link i m loading to a web view.

http://html5videoformatconverter.com/html5-video-tag-example.html

and all i m doing is

  public class VideoActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    WebView mWebView = (WebView) findViewById(R.id.wvVideo);
    mWebView.setWebChromeClient(chromeClient);
    mWebView.getSettings().setJavaScriptEnabled(true);
    mWebView.getSettings().setPluginsEnabled(true);
    mWebView.loadUrl("http://html5videoformatconverter.com/html5-video-tag-example.html");

}
private WebChromeClient chromeClient = new WebChromeClient(){

    @Override
    public void onShowCustomView(View view, CustomViewCallback callback) {
        // TODO Auto-generated method stub
        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);
                           video.start();

            }
        }

    }

};

}

pls help me modify my code. thanks

Upvotes: 3

Views: 22274

Answers (5)

Ananth
Ananth

Reputation: 1998

I was converting my mobile website with youtube embeds into android app....this project helped me get rid of getting the video to fullscreen in webview. All my problems were solved. You can get something from here. https://code.google.com/p/html5webview/

Upvotes: 0

Leo
Leo

Reputation: 1505

When I encountered this problem it was due to the compression type. For android I had to use base profile compression rather than high profile compression. ffmpeg compatibility has a description.

I answered a similar question here.

Upvotes: 0

dokkaebi
dokkaebi

Reputation: 9190

As @Mikko says, this is a tricky area.

One thing to check is that you have hardware acceleration enabled. I encounter the exact same symptoms the OP describes when leaving it turned off.

You can enable it at the application or at the activity level:

<application 
    android:icon="@drawable/icon_72" 
    android:logo="@drawable/icon_menu_72"
    android:label="@string/app_name"
    android:hardwareAccelerated="true"
    >

OR

<activity 
    android:name=".MyActivity"
    android:hardwareAccelerated="true"
    >

Upvotes: 0

droiding
droiding

Reputation: 41

This worked for me, problem was to do with file permissions on the locally stored video. Hope it helps!

<video width="365" height="200" src="/mnt/SDcard/media/video/abc.mp4" controls autobuffer></video>

Upvotes: 2

Mikko Ohtamaa
Mikko Ohtamaa

Reputation: 83768

Android Browser and WebView has many known problems playing HTML5 <video> videos.

Android webview cannot render youtube video embedded via iframe

Unless you can target Android 4.0 or good modern firmwars, the current workaround is to have a thumbnail image link to a video and then this link opens the video in the native Android video player.

For more information with HTML5 video problems on Android please feel free to search stackoverflow.com.

Upvotes: 2

Related Questions