Answer the question
In order to leave comments, you need to log in
What can I do with large audio files so that they can be conveniently listened to on a web page?
Briefly the essence:
there is one tiny project that I do for myself in order to upload audiobooks to the hosting, then listen to them from a phone on which there is always not enough space, and he would remember the time where I stopped listening. Here are the links to the service itself and the github with sources: Github
service
Almost everything that was intended is functioning there, except for the most important one - working with large files. For example, now in the list there is "Crime and Punishment". A 25-hour recording weighs something like 700 MB, and when you try to listen to it (via the ‹audio› tag), you obviously have problems. What problems:
Answer the question
In order to leave comments, you need to log in
I would go by splitting the file into pieces, by the way, this can be automated through ffmpeg.
It is also better to save information about all the pieces and their duration (for example, in json).
For continuous playback, it is worth creating a new audio and inserting it on the page some time before the end of the playback of the current piece. You can track the time through the timeupdate event .
Upon completion of the current piece ( ended event ), launch the next one, and delete the audio element of the current one from the page.
If you need a slider that emulates a full file, then you can make a custom one using information from json. Although for personal use, I personally would not bother and would simply display buttons for switching to the desired piece, still based on information from json.
In you can watch the timestamp and write to localStorage when you pause or when you close the tab.
Or once every 10 seconds, which is easier.
When re-enabled, this flag can be set and the browser will make a request with offset.
And here the magic happens - the browser itself will make a request for the desired section of the file.
https://developer.mozilla.org/en-US/docs/Web/HTTP/...
Naturally, the server should be able to give the file not entirely, but in the necessary pieces, but in the third millennium almost all HTTP servers can do this.
There is also a media fragment uri but this is a newer spec and less common.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question