I have converted my Video file into stream and ran the video in browser using HTML5 Video tag.
Here is code behind file code:
StreamVideo.aspx.vb
Imports System.IO
Public Class StreamVideo
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Context.Response.Buffer = False
Context.Response.ContentType = "video/mp4"
Dim path As String = Context.Server.MapPath("Resources\small.mp4")
Dim fileinfo As FileInfo = New FileInfo(path)
fileinfo.Refresh()
If fileinfo.Exists Then
Dim len As Integer = fileinfo.Length
Dim bytes As Integer
Context.Response.AppendHeader("content-length", len.ToString())
Dim buffer(1024) As Byte
Dim outstream As System.IO.Stream = Context.Response.OutputStream
Using stream As System.IO.Stream = File.OpenRead(path)
bytes = stream.Read(buffer, 0, buffer.Length)
While len > 0 And bytes > 0
outstream.Write(buffer, 0, bytes)
bytes = stream.Read(buffer, 0, buffer.Length)
len -= bytes
End While
End Using
Else
Context.Response.Write("404: file not found")
End If
Context.Response.Flush()
Context.Response.Close()
Context.Response.End()
End Sub
End Class
And I have another
.aspx page that contains html5 video tag in which src of video tag is set to
StreamVideo.aspx which I mentioned above.
<body>
<div>
<video width="400" controls ="controls" id="videoDemo">
<source src="StreamVideo.aspx" type="video/mp4"/>
Your browser does not support HTML5 video.
</video>
</div>
</body>
The issue is, video run only once. When I set
src direct to file path instead of Stream, then video tag works and can be replayed but in case of Stream, it run only once. What changes I need to commit?