我有这个代码
var englishSubtitle = new chrome.cast.media.Track(2,chrome.cast.media.TrackType.TEXT);
englishSubtitle.trackContentId = 'english.vtt';
englishSubtitle.trackContentType = 'text/vtt';
englishSubtitle.subtype = chrome.cast.media.TextTrackType.CAPTIONS;
englishSubtitle.name = 'English';
englishSubtitle.language = 'en-US';
englishSubtitle.customData = null;
var tracks = englishSubtitle;
var mediaInfo = new chrome.cast.media.MediaInfo(app.streamState_.manifest);
mediaInfo.contentType = app.streamState_.type;
mediaInfo.metadata = new chrome.cast.media.GenericMediaMetadata();
mediaInfo.customData = null;
mediaInfo.streamType = chrome.cast.media.StreamType.BUFFERED;
mediaInfo.textTrackStyle = new chrome.cast.media.TextTrackStyle();
mediaInfo.tracks = tracks;
mediaInfo.metadata.metadataType = chrome.cast.media.MetadataType.GENERIC;
var activeTrackIds = [2];
var request = new chrome.cast.media.LoadRequest(mediaInfo);
request.autoplay = true;
request.currentTime = 0;
request.activeTrackIds = activeTrackIds;
session.loadMedia(request,onMediaDiscovered.bind( this, 'loadedMedia'), onMediaError);
我想在Chromecast上显示字幕。当我想根据请求设置ActiveTrack时,我会收到一个错误 object {代码:" session_error",描述:" invalid_params",详细信息:object}它没有显示的字幕,并且视频根本没有播放,这是因为错误。我做错了吗?
tracks
当您设置
mediaInfo.tracks = tracks;
在您的情况下,您应该尝试
var tracks = [englishSubtitle];
,如前所述,使用字幕而不是字幕。最后,即使您使用的是MP4,也要确保您从Web服务器上存在CORS标头。
tracks
应该存储在数组中
https://developers.google.com/cast/docs/reference/chrome/chrome.cast.media.mediainfo#tracks
non-null chrome.cast.media.track
阵列轨道对象的数组。
mediaInfo.tracks = [englishSubtitle, frenchSubtitle, germanSubtitle]
我为Chromecast SDK创建了一个简单的JavaScript包装器:
https://github.com/fenny/chromecastjs
可能值得检查一下您是否偶然发现了更多问题,祝您好运!