feat: 优化字幕事件逻辑,新增字幕加载和更新事件,删除不再使用的字幕切换事件

This commit is contained in:
Harvey Zack committed 2024-09-14 17:30:22 +08:00
1 parent 9b87f9661d
commit 36fb27d7a1
7 files changed
+69 -74

No files matched your search

@@ -580,9 +580,9 @@ art.on('subtitleOffset', (offset) => {
});
```
## `subtitleUpdate`
## `subtitleBeforeUpdate`
当字幕更新时触发
当字幕更新前触发
<div className="run-code">▶ Run Code</div>
@@ -595,8 +595,28 @@ var art = new Artplayer({
},
});
art.on('subtitleUpdate', (text) => {
console.info('subtitleUpdate', text);
art.on('subtitleBeforeUpdate', (cue) => {
console.info('subtitleBeforeUpdate', cue);
});
```
## `subtitleAfterUpdate`
当字幕更新后触发
<div className="run-code">▶ Run Code</div>
```js{9}
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
subtitle: {
url: '/assets/sample/subtitle.srt',
},
});
art.on('subtitleAfterUpdate', (cue) => {
console.info('subtitleAfterUpdate', cue);
});
```
@@ -615,32 +635,8 @@ var art = new Artplayer({
},
});
art.on('subtitleLoad', (url) => {
console.info('subtitleLoad', url);
});
```
## `subtitleSwitch`
当字幕切换时触发
<div className="run-code">▶ Run Code</div>
```js{13}
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
subtitle: {
url: '/assets/sample/subtitle.srt',
},
});
art.on('ready', () => {
art.subtitle.url = '/assets/sample/subtitle.ass';
});
art.on('subtitleSwitch', (url) => {
console.info('subtitleSwitch', url);
art.on('subtitleLoad', (option, cues) => {
console.info('subtitleLoad', option, cues);
});
```
@@ -571,9 +571,10 @@ art.on('subtitleOffset', (offset) => {
console.info('subtitleOffset', offset);
});
```
## `subtitleUpdate`
Triggered when the subtitle updates
## `subtitleBeforeUpdate`
Triggered before subtitles are updated
<div className="run-code">▶ Run Code</div>
@@ -586,8 +587,28 @@ var art = new Artplayer({
},
});
art.on('subtitleUpdate', (text) => {
console.info('subtitleUpdate', text);
art.on('subtitleBeforeUpdate', (cue) => {
console.info('subtitleBeforeUpdate', cue);
});
```
## `subtitleAfterUpdate`
Triggered when the subtitles are updated
<div className="run-code">▶ Run Code</div>
```js{9}
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
subtitle: {
url: '/assets/sample/subtitle.srt',
},
});
art.on('subtitleAfterUpdate', (cue) => {
console.info('subtitleAfterUpdate', cue);
});
```
@@ -606,31 +627,8 @@ var art = new Artplayer({
},
});
art.on('subtitleLoad', (url) => {
console.info('subtitleLoad', url);
});
```
## `subtitleSwitch`
Triggered when subtitles switch
<div className="run-code">▶ Run Code</div>
```js{13}
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
subtitle: {
url: '/assets/sample/subtitle.srt',
},
});
art.on('ready', () => {
art.subtitle.url = '/assets/sample/subtitle.ass';
});
art.on('subtitleSwitch', (url) => {
console.info('subtitleSwitch', url);
art.on('subtitleLoad', (option, cues) => {
console.info('subtitleLoad', option, cues);
});
```