Search code examples
webviewhtml5-videohybrid-mobile-app

where to place local video files for android webview html5 hybrid app


I am loading html page from asset folder to android webview, the html pages has video. Other images are loaded clearly but video is not loaded i mean not plays in app. Where to place the local video file? I tested by placing video files in asset folder and raw folder, but not plays video.

 webView.loadUrl("file:///android_asset/index.html"); // load html file


video.src="file:///android_res/raw/test.mp4"; // load video file from raw folder

and

video.src="file:///android_asset/test.mp4";  // load video file from assets folder

Please help me, thanks in advance.


Solution

  • I placed video files in RAW folder and access video file in default.html file by following code:

    video.src ="android.resource://ProjectPackageAame/raw/test";
    video.type = "video/mp4";      
    video.load(); 
    video.play();
    

    It playes video like i want. Also added following line in AndroidManifest file.

    android:hardwareAccelerated="true"
    

    For playing video in full screen mode used showCustomView & hideCustomView method of WebChromeClient. What i have done is kept one Framelayout(customContainer) in my main.xml, and adding view received in showCustomView here, and removing it in onHide. Also hiding/showing webview accordingly.