I am creating a interactive movie game, and need to play HLS media from the internect. Some videos will be played multiple times and better to be able to cache the data to local so that players do not have to download it again and again. Is it possible to do so?
No, this is not possible.
SInce you are playing a HLS stream, let’s assume you had 3 variants at 1, 2 and 4 Mbps. Now due to available bandwidth on the first playback you get the 2Mbps variant and store some of its segments.
On the next playback you have a better bandwidth and get the 4Mbps variant. Would you want to then switch quality down to 2Mbps for every segment you have already stored just to not download the better one?
And conversely, if you are playing back the 1Mbps from the internet and have some segments stored from the 4Mbps variant, would you want to switch quality up for those?
Especially if every quality change would be perceivable?
Since game consoles tend to have strict rules on accessing the storage medium, this and the aforementioned issues with the different quality levels are the primary reason this is not supported.
You’re best bet will probably be to add caching code to the Engine\Plugins\Media\ElectraPlayer\Source\ElectraPlayerRuntime\Private\Runtime\HTTP\HTTPManager.cpp source code.
All network requests of the Electra player are made through there.
Be advised that it is impossible for you to know which segment URL is pointing to “the same segment of another variant” as segment URLs can be completely random. If the videos are your own then you have control over the file naming scheme and could correlate the media segments of the different variants so you’re only keeping the higher quality ones.
Ideally you would cache everything you are downloading though. Also keep in mind that Electra performs partial GET requests even on a single segment if there is a connection issue and the GET needs to be retried. Only the portions that have not been fetched before will be requested, so you need to fully support partial GET requests.
Thanks. What if when the user/code selected one segment of different quality is not stored locally, we always choose to play from stream and download the segment of new quality? Basicall we can download what is missing, and always play the selected quality. A lot of video website’s software allows the user to cache the video lcoally on there computer I think.
If Epic is not planing to have such support, is there a best place in the codes for us to start with to implement this feature?