Video.js 是一個具有大量功能的流行的視訊和音訊 JavaScript 庫,今天我們試試整合到 Blazor .
https://blazor.app1.es/videoPlayers
dotnet new blazorserver -o b13video
dotnet sln add b13video/b13video.csproj
Pages\_Host.cshtml
參照 video-js.css
<link href="//vjs.zencdn.net/7.10.2/video-js.min.css" rel="stylesheet">
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>
wwwroot
資料夾檔案內容
function loadPlayer(id, options) {
videojs(id, options);
}
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">