asp.net-core - 如何取消视频流 API 请求
问题描述
版本:ASP.NET Core API 2.1.X 与 IIS 和 windows server 2016 一起使用
我正在将视频从 URL 流式传输到目标:
public async Task <IActionResult> Get(string videoID, CancellationToken CT)
{
HttpClient _client = new HttpClient();
CT.ThrowIfCancellationRequested();
try
{
HttpResponseMessage httpRespond = await _client.GetAsync(oneVideo.Uri, HttpCompletionOption.ResponseHeadersRead, CT);
var _stream = await httpRespond.Content.ReadAsAsync<Stream>();
return File(_stream, "video/mp4");
}
catch (System.Exception ex)
{
//Won't trigger when stream is canceled by user, Like close browser.
//TODO: Cancel streams
}
}
我收到以下错误:
System.Net.Http.UnsupportedMediaTypeException:“没有 MediaTypeFormatter 可用于从媒体类型为“video/mp4”的内容中读取“Stream”类型的对象。
网络上的示例对于我的使用来说非常不足或过于复杂。我没有选择。
解决方案
推荐阅读
- matlab - Why notch filter can't remove 50 hz frequency?
- haskell - Haskell,定义类型多态的函数的特化
- spring-boot - Gitlab CI docker镜像在本地无法访问
- c++ - 如何使用 c++ 模型填充播放列表 qml 类型?
- mysql - 在mysql中使用触发器总结两列并找到百分比
- c++ - 我应该使用 std::cerr 和 exit() 而不是抛出异常吗?
- javascript - 获取隐藏输入Vue.Js的自动完成输入值
- android - 泄漏的窗口,但希望在用户单击肯定按钮时完成活动
- f# - 如何为 Saturn 应用程序构建集成测试
- javascript - 试图从 API 中列出用户的最爱,得到“TypeError: null is not an object (evalating 'firebase.auth().currentUser.uid')