I’m wanting the browser to reduce the amount of an audio file that is downloaded at a time.
I’m writing a custom music server with a rust backend. When the URL of an audio element is set, the browser requests the file. One of the request headers is range: bytes=0-
. This indicates that the browser wants to download the entire file. This is problematic because some of these files are quite large (50+mb).
I’ve tried to return part of the file with an accompanying content-range header bytes=0-100
. The browser accepts it and starts playback, but then requests the next range of bytes=100-
immediately. I return the next set of data, and this process continues until the entire file is downloaded. I’m aware that the browser is requesting the entire file, but I don’t know how to change that behavior.
I don’t want to serve the entire file. It is likely that only a small part of a file will be played. How can I tell the browser to stop asking for data before it is needed? Ideally, the browser should request the first 30 seconds, then at 15 seconds request the next 30 seconds, and continue until the file is downloaded.