简体   繁体   English

在 razor 页面中播放 mp4 文件

[英]Playing mp4 files in razor pages

I'm trying to play mp4 video in razor page using resources below:我正在尝试使用以下资源在 razor 页面中播放mp4视频:

Unluckily none of them worked for me.不幸的是,他们都没有为我工作。

Currently I have one mp4 file in root/Videos/one.mp4 and this is how my root/Program.cs looks like:目前我在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();

This is what I already tried in root/Pages/Index.cshtml using following examples.这是我已经使用以下示例在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>

My net --version is 6.0.100我的net --version6.0.100

Can someone help me with that?有人可以帮我吗?

According to the gunr2171's comment.根据gunr2171的评论。 Solution below:解决方案如下:

Instead of keeping one.mp4 file in:而不是将one.mp4文件保存在:

root/Videos/one.mp4

Move it to:将其移至:

root/wwwroot/Videos/one.mp4

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM