WMV streaming file size limit
Asked Answered
G

4

12

I have a windows media player embedded in my web page view:

 <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>

The ShowMovie action extracts a video stream from the database and sends it to the view with this:

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

When I use a video with a size of about 10K or so will play fine. But if I use a file that is about 137K or so the file never plays. Is it too large?

When I use F12 to see the network activity I see the file is trying to come down as text/html. Why is that? I also see that on the GET function that it is aborting. Why is that? I've increased the executionTimeout value to no avail.

enter image description here

The information from napuza was good I was able to get the correct content type and it seems the entire file was streamed to the browser but it never plays.

enter image description here

Glennisglennon answered 24/4, 2017 at 13:28 Comment(0)
B
6

Specify the ContentType:

ControllerContext.HttpContext.Response.ContentType = "video/x-ms-wmv";
ControllerContext.HttpContext.Response.BinaryWrite(bytesinfile);
Backplate answered 1/5, 2017 at 13:56 Comment(2)
Thanks napuza. I now see the correct content type but the large files never play. Is there something else I need to do?Glennisglennon
This is strange but I think it may have been the particular file I loaded into the database. Once I loaded an actual file to be used in the training process, and the file is over 300MB, it played just fine - over 23 minutes!Glennisglennon
B
0

Try to send the file in chunks:

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();
Backplate answered 1/5, 2017 at 17:14 Comment(1)
That helps a little. It goes from locating media to connecting to media to opening media then jumps back to ready without playing anything.Glennisglennon
B
0

You can try to implement HTTP range requests.

Backplate answered 1/5, 2017 at 17:56 Comment(0)
G
0

I've given credit to napuzba for the answer because he led me in the right direction. I succeeded with this:

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

However, some of the WMV files I've been working with still don't play. I suspect it may have something to do with the metadata in the file. Anyone have ideas on that?

Glennisglennon answered 3/5, 2017 at 11:3 Comment(1)
First, check if the original file work from your local disk (URL='file://...'). If so, download the file from the site and compare its contents with the original file.Backplate

© 2022 - 2024 — McMap. All rights reserved.