问题描述
我使用以下代码从服务器读取mp4文件并通过http发送。我的服务器端是一个mvc4控制器。有趣的是Chrome中的视频效果很好。但是在ios设备上没有得到任何东西,所以我认为这可能是一个响应流头问题。我缺少什么?
I am using the following code to read a mp4 file from the server and send it over http. My server side is a mvc4 controller. Funny thing is the video renders fine in Chrome. But not getting anything on ios devices so I am thinking this could be a response stream header problem. Anything I am missing?
var stream = new FileStream(path, FileMode.Open, FileAccess.Read);
var result = new HttpResponseMessage(HttpStatusCode.OK)
{
Content = new StreamContent(stream)
};
result.Content.Headers.ContentType = new MediaTypeHeaderValue("video/mp4");
result.Content.Headers.ContentRange = new ContentRangeHeaderValue(0, stream.Length);
result.Content.Headers.Add("filename", fileName);
return result;
这是响应头,如果它提供任何线索:
This is the response header if it gives any clues:
Cache-Control:no-cache
Content-Length:2236480
Content-Range:bytes 0-2236480/*
Content-Type:video/mp4
Date:Fri, 24 May 2013 14:39:11 GMT
Expires:-1
filename:3.mp4
Pragma:no-cache
Server:Microsoft-IIS/7.5
X-AspNet-Version:4.0.30319
X-Powered-By:ASP.NET
推荐答案
我认为这是iOS设备上的编码器问题。据我所知,iOS iPhone设备使用H.264 mp4编码。您应该为视频尝试Baseline level 3编码。您可以在找到更多信息。 。
I believe this is an encoder issue on iOS devices. iOS iPhone devices from what I know, use H.264 mp4 encoding. You should try Baseline level 3 encoding for the videos. You can find more info here.
这篇关于从C#中读取并发送mp4文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!