我正在寻找一种方法来完成这项工作。 我需要在chromecast上的文件(VTT)中显示字幕。
我有一个带字幕和chromecast插件的VideoJS播放器。
这是我的代码:
key: 'onSessionSuccess',
value: function onSessionSuccess(session) {
var image = undefined;
var key = undefined;
var loadRequest = undefined;
var mediaInfo = undefined;
var ref = undefined;
var value = undefined;
this.apiSession = session;
var source = this.player_.cache_.src;
var type = this.player_.currentType();
_videoJs2['default'].log('Session initialized: ' + session.sessionId + ' source : ' + source + ' type : ' + type);
mediaInfo = new chrome.cast.media.MediaInfo(source, type);
mediaInfo.metadata = new chrome.cast.media.GenericMediaMetadata();
if (this.options_.playerOptions.chromecast.metadata) {
ref = this.options_.playerOptions.chromecast.metadata;
for (key in ref) {
value = ref[key];
mediaInfo.metadata[key] = value;
}
}
//Add poster image on player
var poster = this.player().poster();
if (poster) {
image = new chrome.cast.Image(poster);
mediaInfo.metadata.images = [image];
}
// Load/Add caption tracks
var plTracks = this.player().textTracks();
var remotePlTracks = this.player().remoteTextTrackEls();
var tracks = [];
var i = 0;
var remotePlTrack = undefined;
var plTrack = undefined;
var trackId = 0;
var track = undefined;
if (plTracks) {
for (i = 0; i < plTracks.length; i++) {
plTrack = plTracks.tracks_[i];
remotePlTrack = remotePlTracks && remotePlTracks.trackElements_ && remotePlTracks.trackElements_[i];
trackId++;
track = new chrome.cast.media.Track(trackId, chrome.cast.media.TrackType.TEXT);
track.trackContentId = remotePlTrack ? remotePlTrack.src : '8306c6ae17b9f81708bcdd8e763e3752_2.vtt';
track.subtype = chrome.cast.media.TextTrackType.CAPTIONS;
track.name = plTrack.label;
track.language = plTrack.language;
track.customData = null;
tracks.push(track);
}
mediaInfo.textTrackStyle = new chrome.cast.media.TextTrackStyle();
mediaInfo.textTrackStyle.foregroundColor = '#FFFFFF';
mediaInfo.textTrackStyle.backgroundColor = '#00000060';
mediaInfo.textTrackStyle.edgeType = chrome.cast.media.TextTrackEdgeType.DROP_SHADOW;
mediaInfo.textTrackStyle.windowType = chrome.cast.media.TextTrackWindowType.ROUNDED_CORNERS;
mediaInfo.metadata.title = "O'Ciné - Propulsé par la liberté";
mediaInfo.metadata.subtitle = Nom_du_film;
}
// Load/Add audio tracks
try {
plTracks = this.player().audioTracks();
if (plTracks) {
for (i = 0; i < plTracks.length; i++) {
plTrack = plTracks.tracks_[i];
trackId++;
track = new chrome.cast.media.Track(trackId, chrome.cast.media.TrackType.AUDIO);
track.subtype = null;
track.name = plTrack.label;
track.language = plTrack.language;
track.customData = null;
tracks.push(track);
}
}
} catch (e) {
_videoJs2['default'].log('get player audioTracks fail' + e);
}
if (tracks.length) {
mediaInfo.tracks = tracks;
}
// Request load media source
loadRequest = new chrome.cast.media.LoadRequest(mediaInfo);
loadRequest.autoplay = true;
loadRequest.currentTime = this.player_.currentTime();
this.apiSession.loadMedia(loadRequest, this.onMediaDiscovered.bind(this), this.castError.bind(this));
this.apiSession.addUpdateListener(this.onSessionUpdate.bind(this));
视频和字幕在没有Chromecast的情况下运行良好但是当我启动Chromecast时,视频上没有字幕。
任何人都可以帮助我吗?
由于