alexa - audioPlayer.播放在 Echo Show Now Play 屏幕上显示内容的问题



我在理解如何在 audioPlayer 的"正在播放"屏幕内的 Echo Show 上显示图像时遇到问题。

我目前正在播放音频文件,并希望在"正在播放"屏幕上显示图像。我能够得到的最接近的代码是以下代码,它在音频开始之前显示图像和标题,但随后立即消失,Echo Show 进入"正在播放"屏幕,没有背景图像,也没有元数据。我觉得我很接近,但只是无法理解如何更新"正在播放"屏幕,而不是它之前的屏幕。

这是代码的一部分(如上所述(:

var handlers = {
'LaunchRequest': function() {
this.emit('PlayStream');        
},
'PlayStream': function() {
let builder = new Alexa.templateBuilders.BodyTemplate1Builder();
let template = builder.setTitle('Test Title')
.setBackgroundImage(makeImage('https://link_to_my_image.png'))
.setTextContent(makePlainText('Test Text'))
.build();
this.response.speak('OK.').
audioPlayerPlay(
'REPLACE_ALL', 
stream.url, 
stream.url, 
null, 
0)
.renderTemplate(template);
this.emit(':responseReady');  
}

我一直在看这个页面 https://developer.amazon.com/docs/custom-skills/audioplayer-interface-reference.html 但不明白如何将该页面上的内容的结构转换为我的代码。我假设,从页面上的代码:

{
"type": "AudioPlayer.Play",
"playBehavior": "valid playBehavior value such as ENQUEUE",
"audioItem": {
"stream": {
"url": "https://url-of-the-stream-to-play",
"token": "opaque token representing this stream",
"expectedPreviousToken": "opaque token representing the previous stream",
"offsetInMilliseconds": 0
},
"metadata": {
"title": "title of the track to display",
"subtitle": "subtitle of the track to display",
"art": {
"sources": [
{
"url": "https://url-of-the-album-art-image.png"
}
]
},
"backgroundImage": {
"sources": [
{
"url": "https://url-of-the-background-image.png"
}
]
}
}
}
}

我不知何故需要得到这部分:

"metadata": {
"title": "title of the track to display",
"subtitle": "subtitle of the track to display",
"art": {
"sources": [
{
"url": "https://url-of-the-album-art-image.png"
}
]
},

进入我的代码块:

audioPlayerPlay(
'REPLACE_ALL', 
streamInfo.url, 
streamInfo.url, 
null, 
0)
.renderTemplate(template);

(并且可能会丢失.renderTemplate(template);部分,因为它只会在"正在播放"屏幕加载之前短暂闪烁。

关于如何实现这一目标的任何想法?

谢谢!

更新:

我已将以下内容添加到索引.js:

var metadata = { 
title: "title of the track to display",
subtitle: "subtitle of the track to display",
art: { 
sources: {
url: "https://url-of-the-album-art-image.png"
} 
}
};

并修改了音频播放器如下:

audioPlayerPlay(
'REPLACE_ALL', 
stream.url, 
stream.url, 
null, 
0,
metadata)
.renderTemplate(template);

并修改了响应生成器.js如下所示:

audioPlayerPlay(behavior, url, token, expectedPreviousToken, offsetInMilliseconds, metadata) {
const audioPlayerDirective = {
type : DIRECTIVE_TYPES.AUDIOPLAYER.PLAY,
playBehavior: behavior,
audioItem: {
stream: {
url: url,
token: token,
expectedPreviousToken: expectedPreviousToken,
offsetInMilliseconds: offsetInMilliseconds,   
metadata : metadata 
}
}
};
this._addDirective(audioPlayerDirective);
return this;
}

但是我仍然没有在"正在播放"屏幕上显示任何内容。

由于某种原因,Echo Show 没有实时更新,需要重新启动才能显示元数据变量中传递的任何内容,这就是我没有看到任何结果的原因。

简单地传递这样的变量就可以了。我只需要找出为什么内容卡在"正在播放"屏幕上并需要重新启动才能工作。

var "metadata": {
"title": "title of the track to display",
"subtitle": "subtitle of the track to display",
"art": {
"sources": [
{
"url": "https://url-of-the-album-art-image.png"
}
]
},

只需按如下方式定义您的元数据。并将其作为第 6 个参数传递给 audioPlayerPlay;

"metadata": {
"title": "title of the track to display",
"subtitle": "subtitle of the track to display",
"art": {
"sources": [
{
"url": "https://url-of-the-album-art-image.png"
}
]
},
audioPlayerPlay(
'REPLACE_ALL', 
streamInfo.url, 
streamInfo.url, 
null, 
0,metadata)

附言要使其正常工作,您必须修改节点模块,然后将其压缩并上传到 lambda。

步骤- 转到您的 node_modules\alexa-sdk\lib 并在其中打开 responseBuilder 文件。并按如下方式修改代码-

audioPlayerPlay(behavior, url, token, expectedPreviousToken, offsetInMilliseconds, **metadata**) {
const audioPlayerDirective = {
type : DIRECTIVE_TYPES.AUDIOPLAYER.PLAY,
playBehavior: behavior,
audioItem: {
stream: {
url: url,
token: token,
expectedPreviousToken: expectedPreviousToken,
offsetInMilliseconds: offsetInMilliseconds
},
**metadata : metadata**
}
};
this._addDirective(audioPlayerDirective);
return this;
}

PS - 仅当您使用 alexa-sdk 版本 1 时才需要修改节点模块。

我知道这个问题最初发布已经有好几年了,但对于那些像我这样现在偶然发现这个问题的人,请确保在 play 指令中使用唯一的令牌,因为元数据是使用该令牌缓存的。

请参阅下一节中的黄色重要说明 https://developer.amazon.com/en-US/docs/alexa/custom-skills/audioplayer-interface-reference.html#images

重要提示:给定音频流的元数据由 audioItem.stream.token 包含在 Play 指令中。请注意, 与特定 audioItem.stream.token 关联的元数据可能是 在 Alexa 服务中缓存长达五天,因此更改 元数据(例如其他图像或标题文本的更改( 可能不会立即反映在设备上。例如,您可以 在测试时,如果您尝试使用不同的图像或 同一音频流的标题文本。您可以发送新的播放 指令,使用不同的 audioItem.stream.token 清除缓存。

还有一个带有令牌的示例有效负载:

{
"type": "AudioPlayer.Play",
"playBehavior": "valid playBehavior value such as ENQUEUE",
"audioItem": {
"stream": {     
"url": "https://cdn.example.com/url-of-the-stream-to-play",
"token": "opaque token representing this stream",
"expectedPreviousToken": "opaque token representing the previous stream",
"offsetInMilliseconds": 0,
"captionData":{
"content": "WEBVTTnn00:00.000 --> 00:02.107n<00:00.006>My <00:00.0192>Audio <00:01.232>Captions.n",
"type": "WEBVTT"
}
},
"metadata": {
"title": "title of the track to display",
"subtitle": "subtitle of the track to display",
"art": {
"sources": [
{
"url": "https://cdn.example.com/url-of-the-album-art-image.png"
}
]
},
"backgroundImage": {
"sources": [
{
"url": "https://cdn.example.com/url-of-the-background-image.png"
}
]
}
}
}
}

最新更新