Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Play local Video in webview

I want to play local videos in crosswalk webview. I'm getting the video path from an intent opening my activity, so it could be stored internally or on sd card.

Using this url file:///storage/emulated/0/Download/movies/movie.mp4 i get Failed to load resource: net::ERR_ACCESS_DENIED.

Using input file dialog with URL.createObjectURL(file); it works. But because i know the path, i dont want to select it again manually. Setting the value of input file is forbidden.

Creating a url using the path is also not possible, because it needs file or blob.

Because of possible big filesize its not possible to temporarily copy it to sd card.

This gives me file not found error:

@Override
    public WebResourceResponse shouldInterceptLoadRequest(XWalkView view,
                                                          String url) {
        if(url.contains("file:///storage")){
            try {
                return new WebResourceResponse("video/*", "UTF-8", new FileInputStream(url));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }
            return super.shouldInterceptLoadRequest(view, url);
    }

also i have defined <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

other questions on stackoverflow asking for accessing assets, so i created this new question

like image 260
curtiss Avatar asked Apr 15 '16 23:04

curtiss


People also ask

Does local storage work in WebView?

On Android, LocalStorage works well but only in the current webview. Multiple webviews of the same app can't share the same data with LocalStorage.

What can I use instead of WebView?

Alternatives to WebView If you want to send users to a mobile site, build a progressive web app (PWA). If you want to display third-party web content, send an intent to installed web browsers. If you want to avoid leaving your app to open the browser, or if you want to customize the browser's UI, use Custom Tabs.

Is Android WebView deprecated?

This interface was deprecated in API level 12. This interface is now obsolete.


1 Answers

The problem might be in accessing video file from External storage also make sure you have given read/write Run time permission . Here you can find your solution here and this

like image 126
Amit Sharma Avatar answered Oct 13 '22 20:10

Amit Sharma