How to avoid downloading videos or images from the server as soon as we saw (like storing in cache)?

I have a problem with my application, it is very slow due to the use of videos and images. When I play a video or display images, it takes time to download, the application closes during this time, or it will be forever.
How can I avoid this problem?
After we saw the image or video, it should not be downloaded from the server again, please give me a solution for this (for example, Facebook).

+4
source share
2 answers

You must first load the video or image in the asynctask inner class, so the application freezes at boot time. You are loading into the user interface thread and it freezes your application, AsyncTask is the way to go. Secondly, when the download is completed, you can save the video, image to the SD card, so the next time you do not have to download them again. If you want to watch the video a second time, you only need to find out the name of the file so that you can capture it from the SD card. You can create a method that determines whether the video on the SD card is considered obsolete and delete this file, if true.

Like other comments, AQuery (Android Query) is a library (facilitates conversations like jQuery for javascript) that offers many convenient methods for downloading files and other interesting things. A short Google query for the term AQuery should include tutorials and download sources.

0
source

You can use AndroidVideoCache to cache video during streaming. This allows you to use cached video after one view.

0
source

Source: https://habr.com/ru/post/1501780/


All Articles