Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# WMV流文件大小限制_C#_Asp.net Mvc 4_Video Streaming_Wmv - Fatal编程技术网

C# WMV流文件大小限制

C# WMV流文件大小限制,c#,asp.net-mvc-4,video-streaming,wmv,C#,Asp.net Mvc 4,Video Streaming,Wmv,我的网页视图中嵌入了windows media player: <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-00C

我的网页视图中嵌入了windows media player:

 <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>
当我使用大约10公里大小的视频时,播放效果会很好。但是如果我使用一个137K左右的文件,这个文件就不会播放。它太大了吗

当我使用F12查看网络活动时,我看到文件试图以text/html的形式显示出来。为什么呢?我还在GET函数上看到它正在中止。为什么呢?我增加了executionTimeout的值,但没有效果

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


指定内容类型:

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

尝试将文件分块发送:

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();

您可以尝试实现

我对纳普扎的回答表示赞赏,因为他引导我走上了正确的方向。我成功地做到了这一点:

 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);
    }
 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文件仍然无法播放。我怀疑这可能与文件中的元数据有关。有人对此有想法吗?

谢谢纳普扎。我现在看到了正确的内容类型,但大文件从不播放。还有什么我需要做的吗?这很奇怪,但我想可能是我加载到数据库中的特定文件。一旦我加载了一个用于训练过程的实际文件,并且该文件超过300MB,它就可以正常播放了——超过23分钟!这有点帮助。它从定位媒体到连接媒体再到打开媒体,然后跳回到就绪状态而不播放任何内容。首先,检查原始文件是否可以从本地磁盘工作(URL=)file://...'). 如果是,请从网站下载该文件,并将其内容与原始文件进行比较。