But if I open actual stream (some online radio station), my browser doesn't try to fetch all to play. Just starts and doesn't know when it will end and also I can't reach previous data and absolutely future data.
I want to make stream like this, how can I do it ? How can I stream a media file (mp3, mp4, mkv...) file that the play time is equal to everyone and prevent them to reach past, future and total media length ?
Edit:
I have struggled about this topic a lot. In case someone need help. I did it finally:
When you want to stream data over http/1.1, you want to make sure that the content-length header field is not set and that the transfer-encoding header is set to chunked.
You can check the browser console(especially the network tab) while doing this to see what file types and http headers(both request and response) are used.
Are you using HTTP/2 by any chance? axum defaults to HTTP/1.1, have you enabled the http2 feature in your Cargo.toml? Could you please check the Version field of the response and tell us what the value is? HTTP/2 ignores transfer-encoding. I'm not familiar with how HTTP/2 streaming works, all I know is that it is much more flexible than HTTP/1.1.
Twitch using this kind of stream type, multiple request and octet-stream. I don't know if it's easier than one request, I'm also into that. If this solves my situation.
The common way to do this for video is a protocol like HTTP Live Streaming or MPEG-DASH. In part, this is because video formats are complex, and chances are high that the file you have on disk requires you to seek around to find all the pieces you need to decode the first frame (e.g. .mp4 files often require you to have a directory at the end of the file).
and as a novice of course, I can't find any kind of resource for these kind of things. that's why I'm struggling for weeks. even for basics. Just injecting data to http body took me days for me, I don't even know I had to do this. I destroyed github, search engines, discord servers for weeks to understand what I need to do. If I had chosen JS or other populer languages on web it would be much more easy. There are 8 hours videos that people just codes and explains. I can't even understand what I need to do, maybe because I'm not enough. If somehow I can complete this project I'm going to create resource for people. Dioxus for frontend, axum for backend.It's a university project. Online radio that people can stream and others can listen and chat. Sorry for long message and if it's unnecessary. It was just brain dump for what I have been living.
And that's fine. Usually going down a few levels of abstraction means that you'll have to DIY a lot more, which is more time consuming and potentially more stressful due to the additional complexity.
Going the other way around is a valid approach. Either way you will learn about what's needed for your particular problem domain.