I am trying to stream a mp4 file using ASP/VBscript. I use ADODB.Stream
to lunch the file and some codes to detect that which range is requested by user. The video is being loaded successfully but by clicking on seek bar nothing happens. I have set all Accept-Ranges
, Content-Range
and Content-Length
in response headers:
HTML code:
<video controls>
<source src="video.asp">
</video>
video.asp
filename ="test.mp4"
Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Type = 1
objStream.Open
objStream.LoadFromFile(server.mappath(filename))
sizebyte=objStream.size
Response.ContentType = "video/mp4"
Response.AddHeader "Accept-Ranges", "0-" & sizebyte
'Checking if user requested a range (by clicking on seekbar)
if Request.ServerVariables("HTTP_RANGE")<>"" then
'Cleaning startbyte from (bytes=) and (-)
startbyte=replace(Request.ServerVariables("HTTP_RANGE"),"-","")
startbyte=replace(startbyte,"bytes=","")
Response.AddHeader "Content-Range", "bytes " & startbyte & "-" & sizebyte-1 & "/" & sizebyte
response.AddHeader "Content-Length", (int(sizebyte) - int(startbyte))
else
response.AddHeader "Content-Length", sizebyte
end if
do while not objStream.EOS
response.binarywrite objStream.Read(1024000)
Response.Flush
loop
objStream.Close
Set objStream = Nothing
Response.StatusCode = 206