Fix the bug where the video does not stream to the end in Chrome - #3
Open
schteeben95 wants to merge 2 commits into
Open
Fix the bug where the video does not stream to the end in Chrome #3schteeben95 wants to merge 2 commits into
schteeben95 wants to merge 2 commits into
Conversation
…ted on Version 98.0.4758.109 (Official Build) (x86_64))
devbaraus
reviewed
Apr 16, 2022
devbaraus
left a comment
There was a problem hiding this comment.
I made a few less modifications
async def video_endpoint(range: str = Header(None)):
start, end = range.replace("bytes=", "").split("-")
start = int(start)
end = int(end) if end else start + CHUNK_SIZE_VIDEO
with open(video_path, "rb") as video:
video.seek(start)
data = video.read(end - start)
filesize = video_path.stat().st_size
if end >= filesize:
end = filesize - 1
headers = {
'Content-Range': f'bytes {str(start)}-{str(end)}/{str(filesize)}',
'Accept-Ranges': 'bytes'
}
return Response(data, status_code=206, headers=headers, media_type="video/mp4")
devbaraus
approved these changes
Apr 16, 2022
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The video did not stream to the end. When Chrome requests for the last chunk it freezes and restarts the playback.
This new commit conforms to the RFC as explained here https://stackoverflow.com/questions/3303029/http-range-header