A way to realize the localization of webview resources

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.