我在 Angular 应用程序中使用 Bitmovin 播放器(v8.15)。我已经将播放器配置如下并定义了回调
this._player = new Player(this.videoPlayer.nativeElement, {
...bitmovinConfig,
events: {
// other code removed
[SubtitleAdded]: () => this.triggerCaptionChange(),
// other code removed
},
});
triggerCaptionChange() {
const captions = this._player.subtitles.list() as MediaCaption[];
console.log(captions);
// other code removed
}
Chrome 中的 MediaCaption 看起来像这样(我们基本上扩展了 bitmovin 的 SubtitleTrack 接口并添加了subType
and sideloaded
:
"id": "1",
"url": "https://...myurl_hidden.../DASH/5b95ba67-75bc-4127-bcaa-182a819f649c_WebVTT_eng.vtt",
"kind": "caption",
"lang": "en-US",
"subType": "subtitles",
"sideloaded": true,
"label": "English",
"enabled": true
我们还使用如下配置加载播放器:
async onSourceChange(_: SourceConfig, current: SourceConfig) {
await this._player.load(current);
this.triggerAudioChange();
this.triggerCaptionChange();
...
}
在 Chrome 中current
看起来像这样:
"hls": "https://...urlhidden.../spmx/.../.../Dash/DASH_pertitle-dash.mpd",
"dash": "https://...urlhidden.../spmx/.../...Dash/DASH_pertitle-dash.mpd",
"drm": hidden,
"subtitleTracks": [
{
"enabled": "false",
"id": "1",
"url": "https://...urlhidden.../spmx/.../.../Dash/Subtitles_es_419.vtt",
"kind": "caption",
"label": "es-419",
"lang": "es-419",
"subType": "Subtitles",
"sideloaded": true
},
{
"enabled": "false",
"id": "3",
"url": "https://...urlhidden.../spmx/.../.../Dash/Captions_en_US.vtt",
"kind": "caption",
"label": "es-US",
"lang": "en-US",
"subType": "Captions",
"sideloaded": true
}
],
"options": {
"startTime": 1709
}
在 Safari 中current
看起来像这样(注意,没有dash
键):
"hls": "https://...urlhidden.../spmx/.../.../Apple/HLS_main.m3u8",
"drm": hidden,
"subtitleTracks": [
{
"enabled": "false",
"id": "1",
"url": "https://...urlhidden.../spmx/.../.../Apple/Subtitles_es-419.m3u8",
"kind": "caption",
"lang": "es-419",
"lang": "es-419",
"subType": "SUBTITLES",
"sideloaded": true
},
{
"enabled": "false",
"id": "2",
"url": "https://...urlhidden.../spmx/.../.../Apple/Subtitles_es_419.vtt",
"kind": "caption",
"lang": "es-419",
"lang": "es-419",
"subType": "Subtitles",
"sideloaded": true
},
{
"enabled": "false",
"id": "4",
"url": "https://...urlhidden.../spmx/.../.../Apple/Captions_en-US.m3u8",
"kind": "caption",
"lang": "en-US",
"lang": "en-US",
"subType": "SUBTITLES",
"sideloaded": true
}
{
"enabled": "false",
"id": "5",
"url": "https://...urlhidden.../spmx/.../.../Apple/Captions_en_US.vtt",
"kind": "caption",
"lang": "en-US",
"lang": "en-US",
"subType": "Captions",
"sideloaded": true
}
],
"options": {
"startTime": 1709
}
在 Chrome 中:控制台日志给了我一个包含两个项目的数组。
在 Safari 中:我得到一个空数组。