Custom progressive audio streaming in the browser

Let's say I like to create my own progressive flow mechanics in Javascript, because I find that the browser built into the streaming mechanism is not very accurate, or I like to implement my own native method via WebSocket. I would like to create a buffer that stores already loaded segments of a continuous media file (say, arraybuffer or something like that). Is it possible to play this file even if it is not already loaded from beginning to end?

My only idea was the web audio API, which has a noteOn () function to pre-count the start time of each segment. However, I do not know how hopeless it would be. It also presents a problem that I need to know exactly where the audio files can be safely cut on the server side, so the next part can be decoded without any loss or space. For instance. The mp3 bit stores audio data in adjacent sound frames even in CBR mode, which complicates the work.

+4
source share
1 answer

How about creating a ScriptProcessorNode that comes from your incoming buffers? The biggest problem is that the segments are converted to the original sound samples, but otherwise you could write a simple function in the onaudioprocess event handler , which pulls in the next available block of the buffer and copies it to the output buffers of the node. Since this will be a mechanism on demand, you will not need to worry about playing a time segment.

+3
source

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


All Articles