Skip to content

Commit 380ead0

Browse files
committed
add back to live tooltips
1 parent 4c53f90 commit 380ead0

File tree

3 files changed

+25
-17
lines changed

3 files changed

+25
-17
lines changed

packages/core/src/i18n/zh-CN.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"Volume: %s": "音量:%s",
77
"Mute": "静音",
88
"Speed": "播放速度",
9-
"LIVE": "直播",
9+
"Live": "直播",
10+
"Back to Live": "回到直播",
1011

1112
"Language": "语言",
1213
"Screenshot": "截图",

packages/shaka/src/index.ts

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@ class ShakaPlugin implements PlayerPlugin {
107107
player.emit('error', { pluginName: ShakaPlugin.name, ...event })
108108
})
109109

110+
// eventManager.listen(this.instance, 'play', () => {
111+
// player.$video.currentTime = this.seekRange.end
112+
// })
113+
110114
try {
111115
await this.instance.load(source.src)
112116
} catch (error: any) {
@@ -115,12 +119,28 @@ class ShakaPlugin implements PlayerPlugin {
115119

116120
if (player.options.isLive) {
117121
const button = player.$root.querySelector('[aria-label="time"')?.parentElement
118-
const dot = button?.firstElementChild as HTMLSpanElement
122+
const dot = button?.firstElementChild as HTMLSpanElement | undefined
119123

120-
if (button) {
124+
if (button && dot) {
121125
eventManager.listen(button, 'click', () => {
122126
player.$video.currentTime = this.seekRange.end
123127
})
128+
129+
const backText = player.locales.get('Back to Live')
130+
const updateIsLive = () => {
131+
const timeBehindLiveEdge = this.seekRange.end - player.$video.currentTime
132+
// var streamPosition = Date.now() / 1000 - timeBehindLiveEdge
133+
134+
if (timeBehindLiveEdge > 5) {
135+
dot.style.backgroundColor = '#ccc'
136+
button.ariaLabel = backText
137+
} else {
138+
dot.style.cssText = ''
139+
button.removeAttribute('aria-label')
140+
}
141+
}
142+
143+
this.instance.eventManager.listen(player.$video, 'timeupdate', updateIsLive)
124144
}
125145

126146
//TODO: revert
@@ -148,19 +168,6 @@ class ShakaPlugin implements PlayerPlugin {
148168
else player.$video.currentTime = v
149169
}
150170
})
151-
152-
const updateIsLive = () => {
153-
const timeBehindLiveEdge = this.seekRange.end - player.$video.currentTime
154-
// var streamPosition = Date.now() / 1000 - timeBehindLiveEdge
155-
156-
if (timeBehindLiveEdge > 5) {
157-
dot.style.backgroundColor = '#ccc'
158-
} else {
159-
dot.style.cssText = ''
160-
}
161-
}
162-
163-
this.instance.eventManager.listen(player.$video, 'timeupdate', updateIsLive)
164171
}
165172

166173
if (player.context.ui) {

packages/ui/src/components/ControllerBottom.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ const render = (it: UIInterface, $el: HTMLDivElement) => {
202202
switcher($play, player.isPlaying)
203203
})
204204

205-
const LIVE = player.locales.get('LIVE')
205+
const LIVE = player.locales.get('Live')
206206
player.on('volumechange', () => switcher($volume, player.isMuted))
207207
player.on(['durationchange', 'timeupdate', 'seeking', 'seeked'], () => {
208208
if (player.options.isLive) {

0 commit comments

Comments
 (0)