0

I serve with code below a mp4 file:

import os
from starlette.responses import FileResponse
return FileResponse(
            filename_out,
            media_type="video/mp4",
            filename=os.path.basename(filename_out)
        )

In firefox, chrome and in android it works fine. Unfortunately it doesn't for the AVPlayer (used by the flutter video_player package) in IOS.

I found this thread iOS 10 AVPlayer will not stream video from URL with no extension and with video/mp4 as content type

However, the file extension is provided with the explicit filename and I'm confused about the header stuff. Has anybody similar experience and a solution?

Edit: In filename is e.g. video.mp4 after that with the test.client it looks like:

{'content-type': 'video/mp4', 'content-disposition': 'attachment; filename="video.mp4"', 
'content-length': '5909110', 'last-modified': 'Mon, 10 Feb 2020 21:23:10 GMT', 'etag': 'd4be0ee89866a2fdc6e2c2dc94c4bc21'} 

Attachment feels not right with/without it is a stream and works with common browser player and android but not in IOS. We use the flutter package video_player and _controller.value.initialized is always false with IOS, but true using a direct file from AWS not served by starlette:

 _controller = VideoPlayerController.network('urlWithMp4StreamOrAttachment',);

Thanks in advance, Christian

Christian
  • 193
  • 1
  • 3
  • 13
  • 1
    have you tried passing the content-type header and adding an extension to the filename_out variable – Hedde van der Heide Feb 12 '20 at 19:31
  • Thanks , but no luck see above. – Christian Feb 12 '20 at 21:20
  • 1
    Does the video play in safari browser in a mac ? If it is not playing try using the inspect element and it will show you the exact error. If it is playing in mac safari then move onto iPhone Safari and check the same. It can give you some clue. – Kautham Krishna Feb 13 '20 at 13:09
  • https://imgur.com/eyMAeZE looks like a problem with this range stuff. Changed the header, but still no sucess . {'content-type': 'video/mp4', 'content-range': 'bytes 0-1', 'accept-ranges': 'bytes', 'content-length': '5909110', 'last-modified': 'Mon, 10 Feb 2020 21:23:10 GMT', 'etag': 'd4be0ee89866a2fdc6e2c2dc94c4bc21'} – Christian Feb 13 '20 at 18:09
  • It looks like we have this problem with uvicorn https://developer.apple.com/library/archive/documentation/AppleApplications/Reference/SafariWebContent/CreatingVideoforSafarioniPhone/CreatingVideoforSafarioniPhone.html#//apple_ref/doc/uid/TP40006514-SW6 – Christian Feb 13 '20 at 18:39
  • 1
    You can always resort to serving these files over a proxy, like nginx (which is optimised for file serving) – Hedde van der Heide Feb 13 '20 at 18:59
  • Yes just implement it with this: https://github.com/tiangolo/uwsgi-nginx-docker. I'll give feedback if it works. – Christian Feb 13 '20 at 19:10

1 Answers1

0

It works with nginx see here some configuration details:

https://gist.github.com/nnfuzzy/50151e817d752c9941f83c1770f74626

Christian
  • 193
  • 1
  • 3
  • 13