Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Webview download/cache video

I have a webview in android that goes to website that has a video tag in it. What would be the best way to either download the video or cache it so that it won't download every time it's being played. Couldn't find anything that works.

like image 996
user2715966 Avatar asked Apr 14 '26 08:04

user2715966


1 Answers

Download the video when you load it first time, and store it in your app's data folder. After that intercept the video url request in your webview and stream the video from local.

 @Override
 public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request) {

//Here check whether /request.getUrl().toString()/ is video url, if Yes, then

Get the locally saved video and convert it as inputstream and return as follows,

return new WebResourceResponse(getMimeType(request.getUrl().toString()), "UTF-8", 200, "OK", responseHeaders, inputStream);   
like image 64
Ragu Avatar answered Apr 16 '26 22:04

Ragu