Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
ai_fundub
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
template admin
ai_fundub
Commits
2c73270d
Commit
2c73270d
authored
Jul 28, 2026
by
Jeff nan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat
parent
e24a3855
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
700 additions
and
70 deletions
+700
-70
index.js
form/index.js
+7
-7
defaultData.json
play/defaultData.json
+16
-16
index.css
play/index.css
+244
-4
index.html
play/index.html
+112
-9
index.js
play/index.js
+321
-34
No files found.
form/index.js
View file @
2c73270d
...
...
@@ -28,13 +28,13 @@ document.addEventListener('DOMContentLoaded', () => {
window
.
courseware
.
getData
(
function
(
data
)
{
window
.
air
.
hideAirClassLoading
(
key
,
data
);
if
(
!
data
)
{
// 加载默认数据
$
.
getJSON
(
'
../play/defaultData.json
'
,
function
(
defaultData
)
{
initVueApp
(
defaultData
);
})
return
;
}
//
if (!data) {
//
// 加载默认数据
//
$.getJSON('../play/defaultData.json', function (defaultData) {
//
initVueApp(defaultData);
//
})
//
return;
//
}
//数据加载完,才算页面加载完成
initVueApp
(
data
);
},
key
);
...
...
play/defaultData.json
View file @
2c73270d
{
"videoUrl"
:
"https://teach.cdn.ireadabc.com/
b3be955c80a0b969a9e3166ad9f36ae2
.mp4"
,
"videoUrl"
:
"https://teach.cdn.ireadabc.com/
030999fb68d0f182ac892de8273affd9
.mp4"
,
"playbackRate"
:
1
,
"subtitlesResult"
:
{
"assUrl"
:
"http
://teach.cdn.ireadabc.com/b3be955c80a0b969a9e3166ad9f36ae2
.ass"
,
"srtUrl"
:
"http
://teach.cdn.ireadabc.com/b3be955c80a0b969a9e3166ad9f36ae2
.srt"
,
"vttUrl"
:
"http
://teach.cdn.ireadabc.com/b3be955c80a0b969a9e3166ad9f36ae2
.vtt"
,
"audioUrl"
:
"http
://teach.cdn.ireadabc.com/b3be955c80a0b969a9e3166ad9f36ae2
_audio.wav"
,
"videoUrl"
:
"https://teach.cdn.ireadabc.com/
b3be955c80a0b969a9e3166ad9f36ae2
.mp4"
,
"chineseAssUrl"
:
"http
://teach.cdn.ireadabc.com/b3be955c80a0b969a9e3166ad9f36ae2
_cn.ass"
,
"chineseSrtUrl"
:
"http
://teach.cdn.ireadabc.com/b3be955c80a0b969a9e3166ad9f36ae2
_cn.srt"
,
"chineseVttUrl"
:
"http
://teach.cdn.ireadabc.com/b3be955c80a0b969a9e3166ad9f36ae2
_cn.vtt"
,
"outputVideoUrl"
:
"http
://teach.cdn.ireadabc.com/b3be955c80a0b969a9e3166ad9f36ae2
_with_bilingual_subtitles.mp4"
,
"bilingualAssUrl"
:
"http
://teach.cdn.ireadabc.com/b3be955c80a0b969a9e3166ad9f36ae2
_bilingual.ass"
,
"subtitleJsonUrl"
:
"http
://teach.cdn.ireadabc.com/b3be955c80a0b969a9e3166ad9f36ae2_subtitle
.json"
,
"translatedJsonUrl"
:
"http
://teach.cdn.ireadabc.com/b3be955c80a0b969a9e3166ad9f36ae2_translated
.json"
"assUrl"
:
"http
s://teach.cdn.ireadabc.com/030999fb68d0f182ac892de8273affd9_gmsh
.ass"
,
"srtUrl"
:
"http
s://teach.cdn.ireadabc.com/030999fb68d0f182ac892de8273affd9_gmsh
.srt"
,
"vttUrl"
:
"http
s://teach.cdn.ireadabc.com/030999fb68d0f182ac892de8273affd9_gmsh
.vtt"
,
"audioUrl"
:
"http
s://teach.cdn.ireadabc.com/030999fb68d0f182ac892de8273affd9
_audio.wav"
,
"videoUrl"
:
"https://teach.cdn.ireadabc.com/
030999fb68d0f182ac892de8273affd9
.mp4"
,
"chineseAssUrl"
:
"http
s://teach.cdn.ireadabc.com/030999fb68d0f182ac892de8273affd9_gmsh
_cn.ass"
,
"chineseSrtUrl"
:
"http
s://teach.cdn.ireadabc.com/030999fb68d0f182ac892de8273affd9_gmsh
_cn.srt"
,
"chineseVttUrl"
:
"http
s://teach.cdn.ireadabc.com/030999fb68d0f182ac892de8273affd9_gmsh
_cn.vtt"
,
"outputVideoUrl"
:
"http
s://teach.cdn.ireadabc.com/030999fb68d0f182ac892de8273affd9
_with_bilingual_subtitles.mp4"
,
"bilingualAssUrl"
:
"http
s://teach.cdn.ireadabc.com/030999fb68d0f182ac892de8273affd9_gmsh
_bilingual.ass"
,
"subtitleJsonUrl"
:
"http
s://teach.cdn.ireadabc.com/030999fb68d0f182ac892de8273affd9_subtitle_gmsh
.json"
,
"translatedJsonUrl"
:
"http
s://teach.cdn.ireadabc.com/030999fb68d0f182ac892de8273affd9_translated_gmsh
.json"
},
"vocalResult"
:
{
"noAudioUrl"
:
"http
://teach.cdn.ireadabc.com/b3be955c80a0b969a9e3166ad9f36ae2
_no_audio.mp4"
,
"onlyVocalUrl"
:
"http
://teach.cdn.ireadabc.com/b3be955c80a0b969a9e3166ad9f36ae2
_only_vocal.mp4"
,
"removeVocalUrl"
:
"http
://teach.cdn.ireadabc.com/b3be955c80a0b969a9e3166ad9f36ae2
_remove_vocal.mp4"
"noAudioUrl"
:
"http
s://teach.cdn.ireadabc.com/030999fb68d0f182ac892de8273affd9
_no_audio.mp4"
,
"onlyVocalUrl"
:
"http
s://teach.cdn.ireadabc.com/030999fb68d0f182ac892de8273affd9
_only_vocal.mp4"
,
"removeVocalUrl"
:
"http
s://teach.cdn.ireadabc.com/030999fb68d0f182ac892de8273affd9
_remove_vocal.mp4"
}
}
\ No newline at end of file
play/index.css
View file @
2c73270d
:root
{
--bg-0
:
#10221c
;
--bg-1
:
#1a342b
;
--ink
:
#f3f0e8
;
--ink-dim
:
rgba
(
243
,
240
,
232
,
0.68
);
--accent
:
#d9a441
;
--accent-soft
:
rgba
(
217
,
164
,
65
,
0.18
);
--line
:
rgba
(
243
,
240
,
232
,
0.14
);
--panel
:
rgba
(
10
,
24
,
20
,
0.55
);
--shadow
:
0
24px
80px
rgba
(
0
,
0
,
0
,
0.35
);
--font-display
:
"Sora"
,
"Instrument Sans"
,
sans-serif
;
--font-body
:
"Instrument Sans"
,
"PingFang SC"
,
"Helvetica Neue"
,
sans-serif
;
}
*
{
box-sizing
:
border-box
;
}
html
,
body
{
background
:
#fff
;
margin
:
0
;
min-height
:
100%
;
background
:
radial-gradient
(
1200px
700px
at
15%
-10%
,
rgba
(
217
,
164
,
65
,
0.16
),
transparent
55%
),
radial-gradient
(
900px
600px
at
90%
10%
,
rgba
(
72
,
140
,
118
,
0.22
),
transparent
50%
),
linear-gradient
(
160deg
,
var
(
--bg-0
),
var
(
--bg-1
)
55%
,
#0c1814
);
color
:
var
(
--ink
);
font-family
:
var
(
--font-body
);
}
[
v-cloak
]
{
display
:
none
;
}
.stage
{
position
:
relative
;
min-height
:
100vh
;
padding
:
clamp
(
20px
,
4vw
,
40px
);
display
:
flex
;
flex-direction
:
column
;
align-items
:
center
;
opacity
:
0
;
transform
:
translateY
(
12px
);
transition
:
opacity
0.55s
ease
,
transform
0.55s
ease
;
}
.stage.ready
{
opacity
:
1
;
transform
:
translateY
(
0
);
}
.stage__glow
{
position
:
fixed
;
inset
:
auto
auto
-20%
50%
;
width
:
70vw
;
height
:
40vh
;
transform
:
translateX
(
-50%
);
background
:
radial-gradient
(
circle
,
rgba
(
217
,
164
,
65
,
0.12
),
transparent
70%
);
pointer-events
:
none
;
animation
:
glowPulse
6s
ease-in-out
infinite
;
}
@keyframes
glowPulse
{
0
%,
100
%
{
opacity
:
0.45
;
transform
:
translateX
(
-50%
)
scale
(
1
);
}
50
%
{
opacity
:
0.8
;
transform
:
translateX
(
-50%
)
scale
(
1.08
);
}
}
.brand
{
width
:
min
(
960px
,
100%
);
margin-bottom
:
18px
;
animation
:
riseIn
0.7s
ease
both
;
}
.brand__mark
{
font-family
:
var
(
--font-display
);
font-size
:
clamp
(
28px
,
5vw
,
42px
);
font-weight
:
700
;
letter-spacing
:
-0.03em
;
line-height
:
1.1
;
}
.brand__tag
{
margin
:
6px
0
0
;
color
:
var
(
--ink-dim
);
font-size
:
14px
;
letter-spacing
:
0.04em
;
}
.player
{
width
:
min
(
960px
,
100%
);
animation
:
riseIn
0.8s
ease
0.08s
both
;
}
.player__frame
{
position
:
relative
;
overflow
:
hidden
;
border-radius
:
18px
;
background
:
#000
;
box-shadow
:
var
(
--shadow
);
border
:
1px
solid
var
(
--line
);
}
.player__video
{
display
:
block
;
width
:
100%
;
max-height
:
min
(
68vh
,
540px
);
background
:
#000
;
}
/* 原生单语字幕样式;双语模式由浮层承接 */
.player__video
::cue
{
font-family
:
"Sora"
,
"Instrument Sans"
,
"PingFang SC"
,
sans-serif
;
font-size
:
20px
;
font-weight
:
600
;
color
:
#fff
;
background
:
transparent
;
text-shadow
:
0
2px
10px
rgba
(
0
,
0
,
0
,
0.75
);
}
.subtitle-overlay
{
position
:
absolute
;
left
:
50%
;
bottom
:
12%
;
transform
:
translate
(
-50%
,
8px
);
width
:
min
(
88%
,
820px
);
text-align
:
center
;
pointer-events
:
none
;
opacity
:
0
;
transition
:
opacity
0.22s
ease
,
transform
0.22s
ease
;
text-shadow
:
0
2px
10px
rgba
(
0
,
0
,
0
,
0.75
);
}
#test
{
margin
:
80px
;
}
\ No newline at end of file
.subtitle-overlay.show
{
opacity
:
1
;
transform
:
translate
(
-50%
,
0
);
}
.subtitle-overlay__en
{
font-family
:
var
(
--font-display
);
font-size
:
clamp
(
16px
,
2.4vw
,
24px
);
font-weight
:
600
;
line-height
:
1.35
;
color
:
#fff
;
margin-bottom
:
4px
;
}
.subtitle-overlay__zh
{
font-size
:
clamp
(
14px
,
2vw
,
20px
);
font-weight
:
500
;
line-height
:
1.4
;
color
:
#f6e7c2
;
}
.controls
{
margin-top
:
16px
;
display
:
flex
;
flex-wrap
:
wrap
;
gap
:
14px
20px
;
padding
:
14px
16px
;
border-radius
:
14px
;
background
:
var
(
--panel
);
border
:
1px
solid
var
(
--line
);
backdrop-filter
:
blur
(
10px
);
}
.controls__group
{
display
:
flex
;
align-items
:
center
;
gap
:
10px
;
flex-wrap
:
wrap
;
}
.controls__label
{
color
:
var
(
--ink-dim
);
font-size
:
12px
;
letter-spacing
:
0.08em
;
text-transform
:
uppercase
;
min-width
:
2.5em
;
}
.seg
{
display
:
inline-flex
;
flex-wrap
:
wrap
;
gap
:
6px
;
}
.seg__btn
{
appearance
:
none
;
border
:
1px
solid
var
(
--line
);
background
:
transparent
;
color
:
var
(
--ink
);
font-family
:
var
(
--font-body
);
font-size
:
13px
;
font-weight
:
500
;
padding
:
7px
12px
;
border-radius
:
999px
;
cursor
:
pointer
;
transition
:
background
0.2s
ease
,
border-color
0.2s
ease
,
color
0.2s
ease
,
transform
0.15s
ease
;
}
.seg__btn
:hover:not
(
:disabled
)
{
border-color
:
rgba
(
217
,
164
,
65
,
0.55
);
transform
:
translateY
(
-1px
);
}
.seg__btn.active
{
background
:
var
(
--accent-soft
);
border-color
:
var
(
--accent
);
color
:
#ffe8b0
;
}
.seg__btn
:disabled
{
opacity
:
0.35
;
cursor
:
not-allowed
;
}
.empty
{
width
:
min
(
960px
,
100%
);
margin-top
:
40px
;
color
:
var
(
--ink-dim
);
font-size
:
15px
;
animation
:
riseIn
0.6s
ease
both
;
}
@keyframes
riseIn
{
from
{
opacity
:
0
;
transform
:
translateY
(
14px
);
}
to
{
opacity
:
1
;
transform
:
translateY
(
0
);
}
}
@media
(
max-width
:
640px
)
{
.controls
{
padding
:
12px
;
}
.controls__group
{
width
:
100%
;
}
.subtitle-overlay
{
bottom
:
14%
;
}
}
play/index.html
View file @
2c73270d
<!DOCTYPE html>
<html
lang=
"
en
"
>
<html
lang=
"
zh-CN
"
>
<head>
<meta
charset=
"UTF-8"
>
<meta
name=
"viewport"
content=
"width=device-width, initial-scale=1.0"
>
<meta
http-equiv=
"X-UA-Compatible"
content=
"ie=edge"
>
<title>
h5-template-generator
</title>
<link
href=
"./index.css"
rel=
"stylesheet"
>
<title>
AI Fundub Player
</title>
<link
rel=
"preconnect"
href=
"https://fonts.googleapis.com"
>
<link
rel=
"preconnect"
href=
"https://fonts.gstatic.com"
crossorigin
>
<link
href=
"https://fonts.googleapis.com/css2?family=Instrument+Sans:wght@400;500;600;700&family=Sora:wght@500;600;700&display=swap"
rel=
"stylesheet"
>
<link
href=
"./index.css"
rel=
"stylesheet"
>
<script
type=
"text/javascript"
src=
"//teach.cdn.ireadabc.com/h5template/h5-static-lib/js/jquery-1.12.3.min.js"
></script>
<script
type=
"text/javascript"
src=
"//teach.cdn.ireadabc.com/h5template/h5-static-lib/js/air.js"
></script>
<script
type=
"text/javascript"
src=
"//teach.cdn.ireadabc.com/h5template/h5-static-lib/js/vue.min.js"
></script>
<!-- 引入样式 -->
<link
href=
"//teach.cdn.ireadabc.com/h5template/h5-static-lib/js/element-ui/theme-chalk/index.css"
rel=
"stylesheet"
>
<!-- 引入组件库 -->
<script
src=
"//teach.cdn.ireadabc.com/h5template/h5-static-lib/js/element-ui/index.js"
></script>
</head>
<body>
<h1
id=
"test"
></h1>
</body>
<script
src=
"./index.js"
></script>
</html>
\ No newline at end of file
<div
id=
"app"
v-cloak
>
<div
class=
"stage"
:class=
"{ ready: ready }"
>
<div
class=
"stage__glow"
aria-hidden=
"true"
></div>
<header
class=
"brand"
>
<div
class=
"brand__mark"
>
AI Fundub
</div>
<p
class=
"brand__tag"
>
字幕同步播放
</p>
</header>
<main
class=
"player"
v-if=
"videoSrc"
>
<div
class=
"player__frame"
>
<video
ref=
"video"
class=
"player__video"
:src=
"videoSrc"
:playbackRate=
"playbackRate"
controls
playsinline
crossorigin=
"anonymous"
@
loadedmetadata=
"onVideoReady"
@
ratechange=
"onRateChange"
>
<track
v-if=
"tracks.en"
kind=
"subtitles"
label=
"English"
srclang=
"en"
:src=
"tracks.en"
>
<track
v-if=
"tracks.zh"
kind=
"subtitles"
label=
"中文"
srclang=
"zh"
:src=
"tracks.zh"
>
</video>
<div
class=
"subtitle-overlay"
:class=
"{ show: subtitleMode === 'bilingual' && sourceMode === 'soft' && (activeEn || activeZh) }"
aria-live=
"polite"
>
<div
v-if=
"activeEn"
class=
"subtitle-overlay__en"
>
{{ activeEn }}
</div>
<div
v-if=
"activeZh"
class=
"subtitle-overlay__zh"
>
{{ activeZh }}
</div>
</div>
</div>
<div
class=
"controls"
>
<div
class=
"controls__group"
>
<span
class=
"controls__label"
>
字幕
</span>
<div
class=
"seg"
>
<button
v-for=
"opt in subtitleModes"
:key=
"opt.value"
type=
"button"
class=
"seg__btn"
:class=
"{ active: subtitleMode === opt.value }"
:disabled=
"opt.disabled"
@
click=
"setSubtitleMode(opt.value)"
>
{{ opt.label }}
</button>
</div>
</div>
<div
class=
"controls__group"
>
<span
class=
"controls__label"
>
语速
</span>
<div
class=
"seg"
>
<button
v-for=
"rate in rateOptions"
:key=
"rate"
type=
"button"
class=
"seg__btn"
:class=
"{ active: Number(playbackRate) === rate }"
@
click=
"setPlaybackRate(rate)"
>
{{ rate }}x
</button>
</div>
</div>
<div
class=
"controls__group"
v-if=
"hasHardSubVideo"
>
<span
class=
"controls__label"
>
片源
</span>
<div
class=
"seg"
>
<button
type=
"button"
class=
"seg__btn"
:class=
"{ active: sourceMode === 'soft' }"
@
click=
"setSourceMode('soft')"
>
原片+软字幕
</button>
<button
type=
"button"
class=
"seg__btn"
:class=
"{ active: sourceMode === 'hard' }"
@
click=
"setSourceMode('hard')"
>
烧录字幕片
</button>
</div>
</div>
</div>
</main>
<div
v-else
class=
"empty"
>
<p>
暂无视频数据,请先在配置页生成字幕。
</p>
</div>
</div>
</div>
<script
src=
"./index.js"
></script>
</body>
</html>
play/index.js
View file @
2c73270d
/*
window.courseware.getData(callback, key);
window.air.hideAirClassLoading(key, data);
*/
/*
var
key
=
'
ai_fundub
'
;
window.courseware.getData(callback,key); //用于获取数据
function
toHttps
(
url
)
{
if
(
!
url
||
typeof
url
!==
'
string
'
)
return
''
;
return
url
.
replace
(
/^http:
\/\/
/i
,
'
https://
'
);
}
window.air.hideAirClassLoading(key,data); //页面加载完成时,必须调用此方法,用于隐藏遮罩层
*/
function
cueText
(
cue
)
{
if
(
!
cue
)
return
''
;
// VTTCue#getCueAsHTML / text;兼容纯 text
var
raw
=
cue
.
text
!=
null
?
String
(
cue
.
text
)
:
''
;
return
raw
.
replace
(
/<
[^
>
]
+>/g
,
''
)
.
replace
(
/
\r?\n
/g
,
'
'
)
.
replace
(
/
\s
+/g
,
'
'
)
.
trim
();
}
function
activeCueText
(
track
)
{
if
(
!
track
||
!
track
.
activeCues
||
!
track
.
activeCues
.
length
)
return
''
;
var
parts
=
[];
for
(
var
i
=
0
;
i
<
track
.
activeCues
.
length
;
i
++
)
{
var
t
=
cueText
(
track
.
activeCues
[
i
]);
if
(
t
)
parts
.
push
(
t
);
}
return
parts
.
join
(
'
'
);
}
$
(
function
()
{
window
.
courseware
.
getData
(
function
(
data
)
{
var
payload
=
data
&&
(
data
.
videoUrl
||
data
.
subtitlesResult
)
?
data
:
null
;
//对应模板的名称,这个可以不写,但是最好是能写上,同时开发多个模板的情况下如果不写这个,本地缓存可能会存在混乱
var
key
=
"
h5_test
"
;
$
(
function
(){
window
.
courseware
.
getData
(
function
(
data
){
//数据加载完,才算页面加载完成
//获取数据
if
(
data
&&
data
.
test
){
$
(
"
#test
"
).
html
(
"
Hello
"
+
data
.
test
);
}
else
{
//一般来讲,如果没有获取到数据的话,给一组默认数据,用于演示模板的展示效果,方便别人了解这个模板
$
(
"
#test
"
).
html
(
"
Hello 我是演示信息!
"
);
}
//数据渲染完成后,添加各种交互或者动画效果
//我这里简单做一个渐入渐出效果的例子
var
flag
=
true
;
setInterval
(
function
(){
if
(
flag
){
$
(
"
#test
"
).
fadeIn
(
500
);
}
else
{
$
(
"
#test
"
).
fadeOut
(
500
);
function
boot
(
saved
)
{
initPlayer
(
saved
||
{});
if
(
window
.
air
&&
typeof
window
.
air
.
hideAirClassLoading
===
'
function
'
)
{
window
.
air
.
hideAirClassLoading
(
key
,
saved
||
data
||
{});
}
flag
=
!
flag
;
},
1000
)
}
if
(
payload
)
{
boot
(
payload
);
return
;
}
// 本地演示:无云端数据时读 defaultData.json
$
.
getJSON
(
'
./defaultData.json
'
)
.
done
(
function
(
defaultData
)
{
boot
(
defaultData
);
})
.
fail
(
function
()
{
boot
({});
});
},
key
);
});
function
initPlayer
(
savedData
)
{
var
result
=
(
savedData
&&
savedData
.
subtitlesResult
)
||
{};
var
softVideo
=
toHttps
(
savedData
.
videoUrl
||
result
.
videoUrl
||
''
);
var
hardVideo
=
toHttps
(
result
.
outputVideoUrl
||
''
);
var
enVtt
=
toHttps
(
result
.
vttUrl
||
''
);
var
zhVtt
=
toHttps
(
result
.
chineseVttUrl
||
''
);
var
initialRate
=
Number
(
savedData
.
playbackRate
);
if
(
!
initialRate
||
isNaN
(
initialRate
))
initialRate
=
1
;
window
.
vueApp
=
new
Vue
({
el
:
'
#app
'
,
data
:
{
ready
:
false
,
softVideo
:
softVideo
,
hardVideo
:
hardVideo
,
sourceMode
:
'
soft
'
,
tracks
:
{
en
:
enVtt
,
zh
:
zhVtt
,
},
subtitleMode
:
enVtt
||
zhVtt
?
(
enVtt
&&
zhVtt
?
'
bilingual
'
:
(
enVtt
?
'
en
'
:
'
zh
'
))
:
'
off
'
,
playbackRate
:
initialRate
,
rateOptions
:
[
0.75
,
1
,
1.25
,
1.5
],
activeEn
:
''
,
activeZh
:
''
,
trackBound
:
false
,
},
computed
:
{
videoSrc
:
function
()
{
if
(
this
.
sourceMode
===
'
hard
'
&&
this
.
hardVideo
)
return
this
.
hardVideo
;
return
this
.
softVideo
;
},
hasHardSubVideo
:
function
()
{
return
!!
this
.
hardVideo
;
},
subtitleModes
:
function
()
{
return
[
{
value
:
'
off
'
,
label
:
'
关闭
'
,
disabled
:
false
},
{
value
:
'
en
'
,
label
:
'
英文
'
,
disabled
:
!
this
.
tracks
.
en
},
{
value
:
'
zh
'
,
label
:
'
中文
'
,
disabled
:
!
this
.
tracks
.
zh
},
{
value
:
'
bilingual
'
,
label
:
'
双语
'
,
disabled
:
!
(
this
.
tracks
.
en
&&
this
.
tracks
.
zh
)
},
];
},
},
mounted
:
function
()
{
var
self
=
this
;
this
.
$nextTick
(
function
()
{
self
.
ready
=
true
;
self
.
applyPlaybackRate
();
self
.
bindTracks
(
true
);
});
},
beforeDestroy
:
function
()
{
this
.
unbindTracks
();
},
methods
:
{
onVideoReady
:
function
()
{
this
.
applyPlaybackRate
();
this
.
bindTracks
(
true
);
this
.
applyTrackModes
();
this
.
refreshCues
();
},
onRateChange
:
function
()
{
var
video
=
this
.
$refs
.
video
;
if
(
!
video
)
return
;
// 保持受控语速(避免被系统控件改乱后不同步)
if
(
Math
.
abs
(
video
.
playbackRate
-
Number
(
this
.
playbackRate
))
>
0.001
)
{
this
.
playbackRate
=
video
.
playbackRate
;
}
},
applyPlaybackRate
:
function
()
{
var
video
=
this
.
$refs
.
video
;
if
(
!
video
)
return
;
try
{
video
.
playbackRate
=
Number
(
this
.
playbackRate
)
||
1
;
}
catch
(
e
)
{}
},
setPlaybackRate
:
function
(
rate
)
{
this
.
playbackRate
=
rate
;
this
.
applyPlaybackRate
();
},
setSubtitleMode
:
function
(
mode
)
{
if
(
mode
!==
'
off
'
&&
this
.
sourceMode
===
'
hard
'
)
{
// 软字幕模式才生效;切回原片
this
.
sourceMode
=
'
soft
'
;
this
.
$nextTick
(
this
.
afterSourceSwitch
);
}
this
.
subtitleMode
=
mode
;
this
.
applyTrackModes
();
this
.
refreshCues
();
},
setSourceMode
:
function
(
mode
)
{
if
(
mode
===
this
.
sourceMode
)
return
;
if
(
mode
===
'
hard
'
&&
!
this
.
hardVideo
)
return
;
var
video
=
this
.
$refs
.
video
;
var
current
=
video
?
video
.
currentTime
:
0
;
var
wasPaused
=
video
?
video
.
paused
:
true
;
this
.
unbindTracks
();
this
.
sourceMode
=
mode
;
if
(
mode
===
'
hard
'
)
{
this
.
subtitleMode
=
'
off
'
;
this
.
activeEn
=
''
;
this
.
activeZh
=
''
;
}
else
if
(
this
.
subtitleMode
===
'
off
'
&&
(
this
.
tracks
.
en
||
this
.
tracks
.
zh
))
{
this
.
subtitleMode
=
this
.
tracks
.
en
&&
this
.
tracks
.
zh
?
'
bilingual
'
:
(
this
.
tracks
.
en
?
'
en
'
:
'
zh
'
);
}
var
self
=
this
;
this
.
$nextTick
(
function
()
{
self
.
afterSourceSwitch
(
current
,
wasPaused
);
});
},
afterSourceSwitch
:
function
(
current
,
wasPaused
)
{
var
video
=
this
.
$refs
.
video
;
if
(
!
video
)
return
;
var
t
=
typeof
current
===
'
number
'
?
current
:
video
.
currentTime
;
var
paused
=
typeof
wasPaused
===
'
boolean
'
?
wasPaused
:
video
.
paused
;
var
onMeta
=
function
()
{
video
.
removeEventListener
(
'
loadedmetadata
'
,
onMeta
);
try
{
if
(
t
>
0
&&
isFinite
(
t
))
video
.
currentTime
=
t
;
}
catch
(
e
)
{}
this
.
applyPlaybackRate
();
this
.
bindTracks
(
true
);
this
.
applyTrackModes
();
this
.
refreshCues
();
if
(
!
paused
)
{
var
p
=
video
.
play
();
if
(
p
&&
p
.
catch
)
p
.
catch
(
function
()
{});
}
}.
bind
(
this
);
if
(
video
.
readyState
>=
1
)
onMeta
();
else
video
.
addEventListener
(
'
loadedmetadata
'
,
onMeta
);
},
findTrack
:
function
(
lang
)
{
var
video
=
this
.
$refs
.
video
;
if
(
!
video
||
!
video
.
textTracks
)
return
null
;
for
(
var
i
=
0
;
i
<
video
.
textTracks
.
length
;
i
++
)
{
var
tr
=
video
.
textTracks
[
i
];
if
(
tr
&&
String
(
tr
.
language
||
''
).
toLowerCase
()
===
lang
)
return
tr
;
}
// 回退:按 label
for
(
var
j
=
0
;
j
<
video
.
textTracks
.
length
;
j
++
)
{
var
t2
=
video
.
textTracks
[
j
];
if
(
!
t2
)
continue
;
if
(
lang
===
'
en
'
&&
/english/i
.
test
(
t2
.
label
||
''
))
return
t2
;
if
(
lang
===
'
zh
'
&&
/中文|chinese|zh/i
.
test
(
t2
.
label
||
''
))
return
t2
;
}
return
null
;
},
bindTracks
:
function
(
force
)
{
var
video
=
this
.
$refs
.
video
;
if
(
!
video
)
return
;
if
(
this
.
trackBound
&&
!
force
)
return
;
if
(
force
)
this
.
unbindTracks
();
this
.
_onCueChange
=
this
.
refreshCues
.
bind
(
this
);
this
.
_onTimeUpdate
=
this
.
refreshCues
.
bind
(
this
);
video
.
addEventListener
(
'
timeupdate
'
,
this
.
_onTimeUpdate
);
var
self
=
this
;
var
bound
=
{
en
:
null
,
zh
:
null
};
var
tryBind
=
function
()
{
var
en
=
self
.
findTrack
(
'
en
'
);
var
zh
=
self
.
findTrack
(
'
zh
'
);
if
(
en
&&
bound
.
en
!==
en
)
{
if
(
bound
.
en
)
{
try
{
bound
.
en
.
removeEventListener
(
'
cuechange
'
,
self
.
_onCueChange
);
}
catch
(
e
)
{}
}
en
.
addEventListener
(
'
cuechange
'
,
self
.
_onCueChange
);
bound
.
en
=
en
;
}
if
(
zh
&&
bound
.
zh
!==
zh
)
{
if
(
bound
.
zh
)
{
try
{
bound
.
zh
.
removeEventListener
(
'
cuechange
'
,
self
.
_onCueChange
);
}
catch
(
e
)
{}
}
zh
.
addEventListener
(
'
cuechange
'
,
self
.
_onCueChange
);
bound
.
zh
=
zh
;
}
self
.
_boundTrackRefs
=
bound
;
self
.
trackBound
=
!!
(
bound
.
en
||
bound
.
zh
||
(
video
.
textTracks
&&
video
.
textTracks
.
length
));
self
.
applyTrackModes
();
self
.
refreshCues
();
};
tryBind
();
// 部分浏览器 track 异步加载,短暂重试
setTimeout
(
tryBind
,
300
);
setTimeout
(
tryBind
,
1000
);
},
unbindTracks
:
function
()
{
var
video
=
this
.
$refs
.
video
;
if
(
video
&&
this
.
_onTimeUpdate
)
{
video
.
removeEventListener
(
'
timeupdate
'
,
this
.
_onTimeUpdate
);
}
var
bound
=
this
.
_boundTrackRefs
||
{};
if
(
this
.
_onCueChange
)
{
if
(
bound
.
en
)
{
try
{
bound
.
en
.
removeEventListener
(
'
cuechange
'
,
this
.
_onCueChange
);
}
catch
(
e
)
{}
}
if
(
bound
.
zh
)
{
try
{
bound
.
zh
.
removeEventListener
(
'
cuechange
'
,
this
.
_onCueChange
);
}
catch
(
e
)
{}
}
if
(
video
&&
video
.
textTracks
)
{
for
(
var
i
=
0
;
i
<
video
.
textTracks
.
length
;
i
++
)
{
try
{
video
.
textTracks
[
i
].
removeEventListener
(
'
cuechange
'
,
this
.
_onCueChange
);
}
catch
(
e2
)
{}
}
}
}
this
.
_boundTrackRefs
=
null
;
this
.
trackBound
=
false
;
},
applyTrackModes
:
function
()
{
var
video
=
this
.
$refs
.
video
;
if
(
!
video
||
!
video
.
textTracks
)
return
;
var
enTrack
=
this
.
findTrack
(
'
en
'
);
var
zhTrack
=
this
.
findTrack
(
'
zh
'
);
//在页面加载、事件、动画等都初始化完成后,一定要记得调用此方法,否则模板将是不可用的
window
.
air
.
hideAirClassLoading
(
key
,
data
);
// 单语走浏览器原生轨;双语用 hidden + 自定义浮层
var
useNative
=
this
.
sourceMode
===
'
soft
'
&&
(
this
.
subtitleMode
===
'
en
'
||
this
.
subtitleMode
===
'
zh
'
);
for
(
var
i
=
0
;
i
<
video
.
textTracks
.
length
;
i
++
)
{
var
tr
=
video
.
textTracks
[
i
];
if
(
!
tr
)
continue
;
try
{
if
(
!
useNative
||
this
.
subtitleMode
===
'
off
'
||
this
.
sourceMode
===
'
hard
'
)
{
tr
.
mode
=
'
hidden
'
;
}
else
if
(
this
.
subtitleMode
===
'
en
'
)
{
tr
.
mode
=
tr
===
enTrack
?
'
showing
'
:
'
disabled
'
;
}
else
if
(
this
.
subtitleMode
===
'
zh
'
)
{
tr
.
mode
=
tr
===
zhTrack
?
'
showing
'
:
'
disabled
'
;
}
else
{
tr
.
mode
=
'
hidden
'
;
}
}
catch
(
e
)
{}
}
// 双语:两轨都 hidden,供 activeCues 读取
if
(
this
.
sourceMode
===
'
soft
'
&&
this
.
subtitleMode
===
'
bilingual
'
)
{
if
(
enTrack
)
try
{
enTrack
.
mode
=
'
hidden
'
;
}
catch
(
e3
)
{}
if
(
zhTrack
)
try
{
zhTrack
.
mode
=
'
hidden
'
;
}
catch
(
e4
)
{}
}
},
},
key
);
refreshCues
:
function
()
{
if
(
this
.
sourceMode
!==
'
soft
'
||
this
.
subtitleMode
!==
'
bilingual
'
)
{
// 单语由原生 track 渲染;清空浮层避免叠字
this
.
activeEn
=
''
;
this
.
activeZh
=
''
;
return
;
}
var
enTrack
=
this
.
findTrack
(
'
en
'
);
var
zhTrack
=
this
.
findTrack
(
'
zh
'
);
if
(
enTrack
&&
enTrack
.
mode
===
'
disabled
'
)
enTrack
.
mode
=
'
hidden
'
;
if
(
zhTrack
&&
zhTrack
.
mode
===
'
disabled
'
)
zhTrack
.
mode
=
'
hidden
'
;
})
\ No newline at end of file
this
.
activeEn
=
activeCueText
(
enTrack
);
this
.
activeZh
=
activeCueText
(
zhTrack
);
},
},
});
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment