WMV流媒体文件大小限制

时间:2017-04-24 13:28:54

标签: c# asp.net-mvc-4 video-streaming wmv

我的网页视图中嵌入了一个Windows媒体播放器:

 <div id="divCourseVideo" style="width:100%;margin:0 auto;" class="container">
        <OBJECT style="display:inline-block" ID="CoursePlayer" HEIGHT="400" WIDTH="400" CLASSID="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" type="video/x-ms-wmv">
            <param name='URL' value="@Url.Action("ShowMovie", "OLT", new { courseId = Model.ID })" />
            <param name='autoStart' value="true" />
            <param name='currentPosition' value="false" />
            <param name='showControls' value="true" />
        </OBJECT>


    </div>

ShowMovie操作从数据库中提取视频流,并使用以下内容将其发送到视图:

 public void ShowMovie(string courseId)
    {
        CourseVideo video = Repository.GetCourseVideoStream(courseId);
        var bytesinfile = new byte[video.VideoStream.Length];
        video.VideoStream.Read(bytesinfile, 0, (int)video.VideoStream.Length);
        ControllerContext.HttpContext.Response.BinaryWrite(bytesinfile);
    }

当我使用大约10K左右的视频时,播放效果会很好。但是,如果我使用大约137​​K左右的文件,文件永远不会播放。它太大了吗?

当我使用F12查看网络活动时,我看到文件正在尝试以文本/ html格式显示。这是为什么?我也在GET函数中看到它正在中止。这是为什么?我增加了executionTimeout值无济于事。

enter image description here

来自napuza的信息很好我能够获得正确的内容类型,似乎整个文件都流式传输到浏览器但它从未播放过。

enter image description here

4 个答案:

答案 0 :(得分:6)

指定ContentType:

ControllerContext.HttpContext.Response.ContentType = "video/x-ms-wmv";
ControllerContext.HttpContext.Response.BinaryWrite(bytesinfile);

答案 1 :(得分:0)

尝试以块的形式发送文件:

response = ...    
byte[] buffer = new byte[4096];

response.ContentType = "video/x-ms-wmv";
response.AppendHeader("content-length", video.VideoStream.Length);

while ( response.IsClientConnected) {
    int bytesRead = video.VideoStream.Read(buffer, 0, buffer.Length);
    if (bytesRead == 0 ) {
        break;
    }
    response.OutputStream.Write(buffer, 0, bytesRead);
    response.Flush();
}
response.End();

答案 2 :(得分:0)

您可以尝试实施HTTP range requests

答案 3 :(得分:0)

我得到了napuzba的回答,因为他带领我朝着正确的方向前进。我成功了:

 CourseVideo video = Repository.GetCourseVideoStream(courseId);
        var bytesinfile = new byte[video.VideoStream.Length];
        video.VideoStream.Read(bytesinfile, 0, (int)video.VideoStream.Length);
        byte[] buffer = new byte[4096];
        ControllerContext.HttpContext.Response.ContentType = "video/x-ms-wmv";
        ControllerContext.HttpContext.Response.AppendHeader("content-length", video.VideoStream.Length.ToString());
        video.VideoStream.Seek(0, SeekOrigin.Begin);
        ControllerContext.HttpContext.Response.BinaryWrite(bytesinfile);
        ControllerContext.HttpContext.Response.End();

然而,我一直在使用的一些WMV文件仍然无法播放。我怀疑它可能与文件中的元数据有关。有人对此有什么想法吗?