Recently took over a crosswalk task, need to put xwalkview video resources into the SD card, each time you encounter the same video will be directly read the contents of the SD card.
Just started to think of using Crosswalk's webresourceclient, using the ' shouldinterceptloadrequest ' method provided for URL interception and resource re-return. At first using this replacement image, the HTML page is all right, but when replacing the video, there was a problem, found that the interception was successful, but the return of the resource failed, still read from the HTML in the src of video. After finding the relevant content, found that webview, including Xwalkview are loaded in the HTML video tag, use is MediaPlayer, but MediaPlayer does not support redirection, so using this method for the replacement of the screen resources is not possible.
Then I want to rewrite the video path through JS, but because HTML is a Web page, not local, resulting in a different domain, and not only the domain is different, this is changed from the HTTP protocol to the file protocol, resulting in a ' not allowed to LOAD LOCAL RESOURCE ' ERROR.
The above two roads do not go through, and finally only through the webserver to convert the local resources into Web resources. Webserver implementations can use the Androidasync framework, or NANOHTTPD can. Start a service on the local webserver, while in the HTML will be the path of video with the JS function, in the Android operation of this JS function to dynamically rewrite the path.
Webserver is nearly CPU-fast after the path is set to 127.0.0.1 on Android, basically as a direct operation of local files, but also addresses cross-domain issues and security issues, which can be considered when encountering resources that cannot be replaced with the API.
A way to realize the localization of webview resources