Reputation: 99
I have a list of videos in my iOS app, which I fetch from my API. The list contains video nodes with an mp4 video file url on the server, and as the user scrolls from one video to the next, the next video starts and the earlier video pauses. This all works well, but I need a way to cache mp4 videos to disk, in such a way that when the user tries to seek, I first try serving the sought chunk from my disk cache, and if this is not cached already, I start loading the chunk from the network, and then the chunks are cached to disk while being played. I also need a way to pre cache the next videos, for example if the user starts playing first video, I need to be able to start caching the second video, so that when the second video starts playing, it does so from the cache, to the point upto which the video is cached, and then seamlessly hop to fetching from the server (and of course caching the responses). How do I go about this?
Upvotes: 3
Views: 784
Reputation: 53830
There's no automated way to do this built into the framework. You'll use background NSURLSessions with download tasks and delegate methods.
You can monitor the progress of the downloads, access the temporary files while they download, pause, resume, and cancel them.
Upvotes: 0