Single PHP “exit;” statement prevents HTML5 video in Safari

前端 未结 3 1153
独厮守ぢ
独厮守ぢ 2021-01-19 09:16

Bizarre bug: in a PHP script that serves video files, I have a few test conditions (authenticate token, make sure file exists, etc.) before sending a \"video/mp4\" header an

相关标签:
3条回答
  • 2021-01-19 09:48

    The only reason for it to render a blank page would be that it does in fact enter the exit; statement. You mentioned an authentication token, could that be missing when testing in safari? Firebug and Safari's developer tools can also help you with debugging (check the response headers, etc).

    0 讨论(0)
  • 2021-01-19 09:59

    It turns out that browsers make two requests to a <video> source before playing it. I was only seeing the headers for the first requests, hence my confusion. The reason the video played in Chrome but not Safari is because the agent that makes the 2nd request in Safari ("QuickTime/7.6.6 (qtver=7.6.6;cpu=IA32;os=Mac 10.6.4)") apparently can't read the same $_COOKIEs; whereas with Chrome, the $_COOKIEs are intact across both requests.

    I still have a serious problem, in that the video plays only on desktop browsers, and not on the iPhone. I'm sure it's not an encoding problem, because if I access the MP4 directly, it plays fine; the problem occurs only when the video is outputted through PHP. Anyway, that's another question altogether.

    0 讨论(0)
  • 2021-01-19 10:09

    Without the video/mp4 header, the server will send the default content type header, usually text/html, some browser may look at what's being served and ignore the MIME type.

    Add error_reporting(E_ALL);to the beginning of the script, and use firebug or similar to examine the headers being sent.

    0 讨论(0)
提交回复
热议问题