Skip to content

Commit 97f08a0

Browse files
committed
视频播放功能
1 parent ebb8a8a commit 97f08a0

File tree

4 files changed

+75
-10
lines changed

4 files changed

+75
-10
lines changed

change.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,10 @@
3838
- [x] 管理后台,恢复和优化附件管理功能
3939
- [ ] 如果管理员或者用户是书籍项目所有人,则音视频链接支持直链播放,否则对音视频链接进行一定的防盗链处理
4040
- [ ] 内容阅读页面音频视频播放功能
41-
- [ ] 音频和视频播放倍速控制
41+
- [x] 音频和视频播放倍速控制
4242
- [ ] 音视频名称显示
43-
- [ ] 视频画中画播放
43+
- [x] 视频画中画播放
44+
- [x] 禁止音频和视频直接下载
4445
- [x] 增加和升级API,使小程序和APP支持音频和视频播放,以及图片放大预览
4546
- [x] 优化`html2json`仓库,解析`HTML`内容,使小程序支持音频和视频播放功能,以及图片放大预览功能
4647
- [ ] 检测和隐藏相关功能

controllers/DocumentController.go

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,27 @@ import (
3131
"github.com/boombuler/barcode/qr"
3232
)
3333

34+
var (
35+
videoBoxFmt = `<div class="video-box">
36+
<div class="video-main">
37+
<div class="video-heading">
38+
<div class="video-title">%v</div>
39+
<div class="video-playbackrate">
40+
<select>
41+
<option value="0.7">0.7 倍</option>
42+
<option value="1.0" selected>1.0 倍</option>
43+
<option value="1.2">1.2 倍</option>
44+
<option value="1.5">1.5 倍</option>
45+
<option value="2.0">2.0 倍</option>
46+
</select>
47+
</div>
48+
</div>
49+
<video controls poster="%v" src="%v" controlslist="nodownload" preload="true">%v</video>
50+
</div>
51+
</div>
52+
`
53+
)
54+
3455
//DocumentController struct.
3556
type DocumentController struct {
3657
BaseController
@@ -273,8 +294,13 @@ func (this *DocumentController) Read() {
273294
medias := []string{"video", "audio"}
274295
for _, item := range medias {
275296
query.Find(item).Each(func(idx int, sel *goquery.Selection) {
276-
sel.SetAttr("controlslist", "nodownload")
277-
sel.SetAttr("preload", "true")
297+
title := strings.TrimSpace(sel.Text())
298+
poster, _ := sel.Attr("poster")
299+
src, _ := sel.Attr("src")
300+
if item == "video" {
301+
sel.BeforeHtml(fmt.Sprintf(videoBoxFmt, title, poster, src, title))
302+
}
303+
sel.Remove()
278304
})
279305
}
280306

static/css/bookstack.css

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1175,12 +1175,7 @@ li.L1, li.L3, li.L5, li.L7, li.L9{background-color: transparent;}
11751175
.markdown-body audio,.markdown-body video{
11761176
max-width: 100%;
11771177
width: 480px;
1178-
display: block;
1179-
margin: 15px 0;
1180-
cursor: pointer;
11811178
}
1182-
.markdown-body video{border-radius: 5px;}
1183-
11841179

11851180
.editormd-preview-container ol.linenums li code, .editormd-html-preview ol.linenums li code{
11861181
display: block;
@@ -1426,4 +1421,43 @@ li.L1, li.L3, li.L5, li.L7, li.L9{background-color: transparent;}
14261421
position: absolute;
14271422
right: 0;
14281423
top: 0;
1424+
}
1425+
1426+
.video-box{
1427+
display: block;
1428+
margin: 15px 0;
1429+
}
1430+
.video-main{
1431+
position: relative;
1432+
display: inline-block;
1433+
}
1434+
.video-heading{
1435+
position: absolute;
1436+
width: 100%;
1437+
background-color: rgba(0,0,0,0.3);
1438+
color: #fff;
1439+
height: 35px;
1440+
line-height: 35px;
1441+
overflow: hidden;
1442+
text-overflow: ellipsis;
1443+
box-sizing: border-box;
1444+
padding: 0 5px;
1445+
font-size: 14px;
1446+
}
1447+
.video-heading.hide{
1448+
display: none;
1449+
}
1450+
.video-main:hover .video-heading.hide{
1451+
display: block;
1452+
}
1453+
.video-title{margin-right: 65px;text-overflow: ellipsis;overflow: hidden;}
1454+
.video-playbackrate{position: absolute;top: 0;right: 0;z-index: 999;height: 35px;}
1455+
.video-playbackrate select{
1456+
line-height: 35px;
1457+
border: 0;
1458+
height: 35px;
1459+
position: relative;
1460+
top: -1px;
1461+
background: rgba(0,0,0,0.3);
1462+
color: #fff;
14291463
}

static/js/bookstack.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,6 @@ $(function () {
473473
break;
474474
case 39:
475475
var href=$(".hung-next a").attr("href");
476-
console.log("right",href);
477476
if(!$(".hung-next").hasClass("hidden") && href!="#"){
478477
load_doc(href,"");
479478
}
@@ -487,4 +486,9 @@ $(function () {
487486
load_doc(location.pathname,"",true);
488487
}
489488
}
489+
490+
$("body").on("change", ".video-playbackrate select", function(e){
491+
var _this =$(this),val = _this.val(),video = _this.parents(".video-main").find("video");
492+
if (video.length>0) video[0].playbackRate = val
493+
})
490494
});

0 commit comments

Comments
 (0)