変換されたビデオを再生できるようにする HTML5 VIDEO タグを含むテスト ページを作成しようとしています。ビデオを変換してサーバーにローカルに保存することはできますが、別の .aspx ページを介してすべてのビデオをストリーミングできるようにしたいと考えています。
HTMLコードを含むplayer.aspxページと、ビデオバイナリを提供する以外は何もしないgetvideo.aspxページがあると仮定すると、次のコードは私のplayer.aspxページでうまく機能すると思いました:
<div style="text-align:center">
<video controls autoplay id="video1" width="920">
<source src="http://www.mywebsite.com/getvideo.aspx?getvideo=1" type="video/mp4">
Your browser does not support HTML5 video.
</video>
getvideo.aspx ページには、次の vb.net コードが含まれています。
Response.clearheaders
Response.AddHeader("Content-Type", "video/mp4")
Response.AddHeader("Content-Disposition", "inline;filename=""newvideo.mp4""")
dim Err as string = ""
Dim iStream As System.IO.Stream
' Buffer to read 10K bytes in chunk:
Dim buffer(buffersize) As Byte
' Length of the file:
Dim length As Integer
' Total bytes to read:
Dim dataToRead As Long
' Identify the file to download including its path.
Dim filepath As String = "./outout/videos/newvideo.mp4"
' Identify the file name.
Dim filename As String = System.IO.Path.GetFileName(filepath)
' Open the file.
try
iStream = New System.IO.FileStream(filepath, System.IO.FileMode.Open, IO.FileAccess.Read, IO.FileShare.Read)
catch ex as exception
throw new exception("Could not create FileStream for [" & filepath & "], error follows." & vbcrlf & ex.toString)
end try
Try
' Total bytes to read:
dataToRead = iStream.Length
' Read the bytes.
While dataToRead > 0
' Verify that the client is connected.
If system.web.httpcontext.current.Response.IsClientConnected Then
' Read the data in buffer
length = iStream.Read(buffer, 0, buffersize)
' Write the data to the current output stream.
system.web.httpcontext.current.Response.OutputStream.Write(buffer, 0, length)
' Flush the data to the HTML output.
system.web.httpcontext.current.Response.Flush()
ReDim buffer(buffersize) ' Clear the buffer
dataToRead = dataToRead - length
Else
'prevent infinite loop if user disconnects
dataToRead = -1
End If
End While
Catch ex As Exception
' Trap the error, if any.
err = "Error accessing " & filepath & " : " & ex.tostring
Finally
If IsNothing(iStream) = False Then
' Close the file.
iStream.Close()
End If
End Try
if err<>"" then throw new exception( err )
ページ出力に表示されるのは、タイムアウトしたように見える HTML ビデオ プレーヤー (Chrome の基本プレーヤー) だけで、[再生] ボタンが灰色になります。Chrome デベロッパー ツールのネットワーク ツールは、45 MB をダウンロードしていることを示し、200 応答コードを取得します。これは、それがうまく機能していることを私に示唆しています。「キャンセル済み」ステータスの 2 番目の GET リクエストを受け取りましたが?
www.mywebsite.com/output/videos/myvideo.mp4 にアクセスすると、ブラウザで正常に再生されるので、IIS がビデオを正しくストリーミングするように構成されていることがわかります。
また、応答コンテンツの配置を「添付ファイル」に変更すると、ブラウザは ASPX ページに移動したときにビデオのダウンロードを正しく強制しますが、これも HTML プレーヤーで正しく再生されません。.aspx ファイルが .net 経由でビデオを提供するのを止めている HTML5 VIDEO タグで何か「賢い」ことが起こっていますか? または、応答ヘッダーがありませんか?
ありがとう!