在剃须刀页中播放mp4文件


我正在尝试使用以下资源在razor页面中播放mp4视频:
  • 在ASP.NET网页(Razor(网站中显示视频
  • 如何使用HTML5在ASP.NET CORE中播放视频
  • 在ASP.Net MVC中使用HTML5视频播放器播放(实时流(视频文件(MP4(
  • 如何使用ASP.NET MVC 5动态上传和播放视频文件
  • HTML视频

不幸的是,他们都不为我工作。

当前我在root/Videos/one.mp4中有一个mp4文件,这就是我的root/Program.cs的样子:
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddRazorPages().AddRazorRuntimeCompilation();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthorization();
app.MapRazorPages();
app.Run();
这是我已经在root/Pages/Index.cshtml中使用以下示例进行的尝试
@page
@model IndexModel
@{
ViewData["Title"] = "Home page";
}
<div class="text-center">
<h1>Embedded Video Example</h1>
<p>The following video provides an introduction to WebMatrix:</p>
<!-- example 1 -->
<video id="VideoPlayer" src="~/Videos/one.mp4" type="video/mp4" controls="true"
width="400" height="350" loop="true"/>
<!-- example 2 -->
<video id="VideoPlayer" src=@Url.Content("~/Videos/one.mp4")" type="video/mp4" controls="true"
width="400" height="350" loop="true"/>
<!-- example 3 -->
<video id="VideoPlayer" controls="true" width="400" height="350">
<source src="~/Videos/one.mp4" type="video/mp4">
</video>
<!-- example 4 -->
<video id="VideoPlayer" controls="true" width="400" height="350">
<source src="@Url.Content("~/Videos/one.mp4")" type="video/mp4">
</video> 
<!-- example 5 -->
<iframe width="560" height="315" src="~/Videos/one.mp4" frameborder="0" type="video/mp4"
allowfullscreen></iframe>
<!-- example 6 -->
<iframe width="560" 
height="315"
type="video/mp4"
src="@Url.Content("~/Videos/one.mp4")" 
frameborder="0" 
allowfullscreen></iframe>
</div>

我的net --version6.0.100

有人能帮我吗?

根据枪2171的评论。以下解决方案:

而不是将one.mp4文件保存在:

root/Videos/one.mp4

将其移动到:

root/wwwroot/Videos/one.mp4

,然后在cshtml:
中使用
<video id="VideoPlayer" src="~/videos/one.mp4" controls width="450" height="450" loop />

最新更新