英文:
How to load metadata directly from chromecast receiver?
问题
我尝试使用以下代码从发送方发送元数据到接收方,代码正常运行。
const mediaInfo = new chrome.cast.media.MediaInfo(url, type);
/* --------------------------------------------- */
mediaInfo.metadata = new chrome.cast.media.GenericMediaMetadata();
mediaInfo.metadata.metadataType = chrome.cast.media.MetadataType.GENERIC;
mediaInfo.metadata.title = title;
/* --------------------------------------------- */
const request = new chrome.cast.media.LoadRequest(mediaInfo);
但现在我尝试在接收方内部进行API调用,并尝试直接从接收方加载元数据。
是否有方法可以这样做?
如果可以,如何操作?我查阅了很多Chromecast接收方设置页面,但没有找到这样做的方法。
非常感谢您的帮助。谢谢。
英文:
I tried sending metadata from the sender to the receiver using the following code which is working fine.
const mediaInfo = new chrome.cast.media.MediaInfo(url, type);
/* --------------------------------------------- */
mediaInfo.metadata = new chrome.cast.media.GenericMediaMetadata();
mediaInfo.metadata.metadataType = chrome.cast.media.MetadataType.GENERIC;
mediaInfo.metadata.title = title;
/* --------------------------------------------- */
const request = new chrome.cast.media.LoadRequest(mediaInfo);
But now I am trying to make an api call inside the receiver itself and trying to load metadata directly right from the receiver itself.
Is there a way to do that?
If so how to do that? I went through so many pages of chromecast receiver setup and couldn't find a way to do that.
Your help is largely appreciated. Thanks.
答案1
得分: 1
你需要在加载时使用 setMessageInterceptor
,调用 API 并将数据设置到 metaData
中,然后添加到 loadRequestData
中。
最后返回 loadRequestData
。
const context = cast.framework.CastReceiverContext.getInstance();
const MediaMetadata = new cast.framework.messages.MediaMetadata();
const playerManager = context.getPlayerManager();
playerManager.setMessageInterceptor(
cast.framework.messages.MessageType.LOAD, loadRequestData => {
return fetch('thirdpartyapi')
.then(response => response.json())
.then(data => {
MediaMetadata.title = '你的标题'
MediaMetadata.subtitle = '你的副标题'
loadRequestData.media.metadata = MediaMetadata
return loadRequestData;
})
});
英文:
You need to use setMessageInterceptor
on load and call the api and set the data on metaData and add to loadRequestData
last return the loadRequestData
const context = cast.framework.CastReceiverContext.getInstance();
const MediaMetadata = new cast.framework.messages.MediaMetadata()
const playerManager = context.getPlayerManager();
/* --------------------------------------------- */
playerManager.setMessageInterceptor(
cast.framework.messages.MessageType.LOAD, loadRequestData => {
return fetch('thirdpartyapi')
.then(response => response.json())
.then(data => {
MediaMetadata.title = 'your.Title'
MediaMetadata.subtitle = 'your.Subtitle'
/* --------------------------------------------- */
loadRequestData.media.metadata = MediaMetadata
/* --------------------------------------------- */
return loadRequestData;
})
});
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论