【发布时间】:2018-12-22 03:29:45
【问题描述】:
在 ASP.NET Core 中流式传输视频时遇到问题
我的视频时长:1:04 当我流式传输此视频时,我想向用户显示 26 秒(40% - 视频长度)
using (var fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite, 65536, FileOptions.Asynchronous | FileOptions.SequentialScan))
{
int totalSize = (int)(fileStream.Length*0.4);
//here we are saying read bytes from file as long as total size of file
//is greater then 0
while (totalSize > 0)
{
int count = totalSize > bufferSize ? bufferSize : totalSize;
//here we are reading the buffer from orginal file
int sizeOfReadedBuffer = fileStream.Read(buffer, 0, count);
//here we are writing the readed buffer to output//
await outputStream.WriteAsync(buffer, 0, sizeOfReadedBuffer);
//and finally after writing to output stream decrementing it to total size of file.
totalSize -= sizeOfReadedBuffer;
}
//outputStream.Position = 0;
}
outputstream 通过 Response.Body 返回流
var stream = context.HttpContext.Response.Body;
但是当响应 html video 标签时,它总是显示持续时间 1:04。我想将此视频的持续时间设置为 26 秒 (40%)
请帮帮我!!!
【问题讨论】:
标签: html asp.net-core video-streaming html5-video