Read and send a mp4 file from in C#

我们两清 提交于 2019-12-24 08:39:08

问题


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

回答1:


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.



来源:https://stackoverflow.com/questions/16736439/read-and-send-a-mp4-file-from-in-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!