我在Angular App中使用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 看起来像这样(我们基本上扩展了 bitmoin 的 SubtitleTrack 界面并添加了subType
和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 中:我得到一个空数组。
我能够联系Bitmovin,经过与他们的一些讨论,我不得不加载SubtitleNative模块(bitmovinplayer-subtitles-native(。确保在字幕模块(bitmovinplayer-字幕(之后加载它
import BitmovinSubtitlesNativeModule from 'bitmovin-player/modules/bitmovinplayer-subtitles-native';
Player.addModule(BitmovinSubtitlesNativeModule);
当我这样做时,我的旁加载条目是由bitmovin'加载的。 但是,在 Safari 上,我添加到 subtitleTracks[] 中的自定义"子类型"和"侧加载"字段被剥离了。 (我们使用它们来帮助区分哪些轨道是旁加载的,哪些是玩家从清单中加载的。
我们决定将我们的子类型和侧加载值编码到字幕轨道的label
字段中。现在,我们可以在自定义播放器 UI 中显示这些旁加载的字幕选项。
现在,Bitmovin 播放器调用我的 onCueEnter/Exit 回调来渲染字幕文本!