Re:Create a Simple Music Streaming App with Flask
by rahimnathwani on Monday December 09, 2013 @03:12AM
(#6873314)
I saw 'streaming' in the title and assumed you were going to use Flask's support for streaming (http://flask.pocoo.org/docs/patterns/streaming/). It allows you to send an HTTP response gradually, using a Python generator. It's useful when:
1) You cannot know the whole response at the time of the request (e.g. streaming news updates).
2) It's computationally expensive to calculate the whole response, and you don't want to make the user wait and/or calculate something that ends up not being used (e.g. if the user cancels the request).
3) You want to save bandwidth. If I were streaming music to you, and allowed you to switch tracks whenever you wanted, then I might not want your browser to start downloading the entire track (faster-than-real-time) when you click play. If I did, and you only listen to half-songs, then I would use twice as much bandwidth. I could release in shorter chunks and put a sleep or something before the yield in the generator function.
1) You cannot know the whole response at the time of the request (e.g. streaming news updates). 2) It's computationally expensive to calculate the whole response, and you don't want to make the user wait and/or calculate something that ends up not being used (e.g. if the user cancels the request). 3) You want to save bandwidth. If I were streaming music to you, and allowed you to switch tracks whenever you wanted, then I might not want your browser to start downloading the entire track (faster-than-real-time) when you click play. If I did, and you only listen to half-songs, then I would use twice as much bandwidth. I could release in shorter chunks and put a sleep or something before the yield in the generator function.