【发布时间】:2020-04-22 23:02:42
【问题描述】:
我遇到过这个问题: 我刚开始学习 ASP.NET,创建了一个简单的应用程序,我需要在其中一个页面上播放视频,这是 cshtml 中的代码:
@{
ViewBag.Title = "Player";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<video width="1020" height="780" controls="controls">
<source src="file:///E:/Video/ActCAM/test2.mp4" type="video/mp4"/>
</video>
<h2>Player</h2>
不幸的是,我看到的只是一个黑盒子,上面有一些不起作用的控件,而不是视频。 (我发现了一个类似的问题 html5 video is not playing mp4 error "Invalid Source"? ,但这对我不起作用)
我在本地 PC 上指定了一个文件仅用于测试,Web 应用程序也在本地计算机上运行。但是,如果我将"file:///E:/Video/ActCAM/test2.mp4" type="video/mp4" 更改为:http://techslides.com/demos/sample-videos/small.mp4(这只是在互联网上找到的免费视频示例),它可以正常工作。此外,如果我只使用以下代码创建一个简单的 HTML 文件:
<video width="1020" height="780" controls="controls">
<source src="file:///E:/Video/ActCAM/test2.mp4" type="video/mp4"/>
</video>
它工作正常。 请帮帮我!
【问题讨论】:
-
从网络服务器提供网页时,您不能使用
file://URI,即使它是localhost。当直接从磁盘打开网页时,您可以使用file://URI。