Video.js 是一个具有大量功能的流行的视频和音频 JavaScript 库,今天我们试试集成到 Blazor .
Blazor VideoPlayer 视频播放器 组件
示例
https://blazor.app1.es/videoPlayers
1. 新建工程b13video
dotnet new blazorserver -o b13video
2. 将项目添加到解决方案中:
dotnet sln add b13video/b13video.csproj
3. Pages\_Host.cshtml
引用 video-js.css
<link href="//vjs.zencdn.net/7.10.2/video-js.min.css" rel="stylesheet">
4. 接下来,Pages\_Host.cshtml
引用 Video.js
, 添加以下脚本文件到Pages\_Host.cshtml
<script src="https://vjs.zencdn.net/7.10.2/video.js"></script>
<script src="https://unpkg.com/video.js/dist/video.min.js"></script>
<script src="https://unpkg.com/@@videojs/http-streaming/dist/videojs-http-streaming.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/videojs-youtube/2.6.1/Youtube.min.js"></script>
5. 添加 app.js 文件到 wwwroot
文件夹
文件内容
function loadPlayer(id, options) {
videojs(id, options);
}
6. Pages\_Host.cshtml
引用 app.js
<script src="./app.js"></script>
完整文件看起来应该是这样
@page "/"
@using Microsoft.AspNetCore.Components.Web
@namespace b13video.Pages
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<base href="~/" />
<link rel="stylesheet" href="css/bootstrap/bootstrap.min.css" />
<link href="css/site.css" rel="stylesheet" />
<link href="b13video.styles.css" rel="stylesheet" />
<link rel="icon" type="image/png" href="favicon.png" />
<link href="//vjs.zencdn.net/7.10.2/video-js.min.css" rel="stylesheet">
<component type="typeof(HeadOutlet)" render-mode="ServerPrerendered" />
</head>
<body>
<component type="typeof(App)" render-mode="ServerPrerendered" />
<div id="blazor-error-ui">
<environment include="Staging,Production">
An error has occurred. This application may no longer respond until reloaded.
</environment>
<environment include="Development">
An unhandled exception has occurred. See browser dev tools for details.
</environment>
<a href="" class="reload">Reload</a>
<a class="dismiss">
标签:set,string,自做,get,JsonPropertyName,VideoPlayer,Blazor,Parameter,public
From: https://www.cnblogs.com/densen2014/p/16981092.html