refactor(videos): 将视频播放器代码移至模板页面

- 将 video.js 文件中的代码复制到每个视频页面的 <script> 标签中
- 更新视频标题、描述和 URL 的变量赋值方式
- 添加下载视频功能
- 修正 4bWST-birthday 视频的 URL
- 删除 video.js 文件
This commit is contained in:
2025-02-14 12:34:30 +08:00
Unverified
parent 43b48bbde0
commit 5f89c68242
4 changed files with 153 additions and 59 deletions

View File

@@ -9,6 +9,8 @@
var videoTitle = "MC统一认证设置教程";
var videoUrl = "./2025-02-14-11-09-11_Notepad3_D0VfI8Cj2L.mp4";
var videoDescription = "此教程将演示如何在PCL2中设置MC统一认证登录\n提醒此视频为分节视频";
</script>
</head>
@@ -26,7 +28,56 @@
<!-- 引入 artplayerPluginChapter 插件 -->
<script src="https://cdn.jsdelivr.net/npm/artplayer-plugin-chapter/dist/artplayer-plugin-chapter.js"></script>
<link rel="stylesheet" href="/videos/video.css">
<script src="/videos/video.js"></script>
<script>
document.getElementById('videoTitle').innerText = videoTitle;
document.getElementById('pageTitle').innerText = videoTitle + " - 播放";
document.getElementById('videoDescription').innerText = videoDescription;
var art = new Artplayer({
container: '.artplayer-app',
url: videoUrl,
autoSize: true,
fullscreen: true,
fullscreenWeb: true,
miniProgressBar: true,
autoOrientation: true,
autoplay: false, // 禁用自动播放
muted: false, // 不自动静音
setting: true,
aspectRatio: true,
fullscreen: true,
lang: 'zh-cn',
fastForward: true,
plugins: [
artplayerPluginChapter({
chapters: [
{ start: 0, end: 18, title: '1' },
{ start: 18, end: 36, title: '2' },
{ start: 36, end: 54, title: '3' },
{ start: 54, end: 72, title: '4' },
{ start: 72, end: Infinity, title: '5' },
]
}),
],
});
function downloadVideo() {
fetch(videoUrl)
.then(response => response.blob())
.then(blob => {
const link = document.createElement('a');
link.href = URL.createObjectURL(blob);
link.download = videoTitle + '.mp4'; // 设置下载文件名
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
URL.revokeObjectURL(link.href);
})
.catch(error => console.error('Error downloading the video:', error));
}
</script>
</body>
</html>