如何在Google Home Hub中启用音乐操作的下一个按钮

时间:2019-06-23 04:38:02

标签: node.js actions-on-google google-home

我正在开发音乐动作。我使用MediaObject返回并播放音频。 当我尝试在Google Home Hub上执行操作时,屏幕底部在2个按钮上分别显示了下一个和上一个按钮。尽管音频更多,我可以说另一个音频的“下一步”,但两个按钮均被禁用。如何启用它? 预先感谢!

two muppets

app.intent('Default Welcome Intent', async (conv) => {
    console.log(`Welcome: ${conv.user.last.seen}`);
    // Check if the device supports media playback
    if (!conv.surface.capabilities.has('actions.capability.MEDIA_RESPONSE_AUDIO')) {
        conv.close('Sorry, this device does not support audio playback.');
        return;
    }

    let audioData = await fetchData()

    // Initialize the index of first audioData
    console.log('Initialize the index for first time')
    conv.user.storage.track = 1
    conv.user.storage.audioData = audioData

    conv.ask(getRandomPrompt(conv, 'welcome'));
    // conv.ask(getRandomPrompt(conv, 'intro'));
    nextTrack(conv);
});

const nextTrack = (conv) => {
    console.log(`nextTrack: ${conv.user.storage.track}`);
    let audioData = conv.user.storage.audioData
    let track = audioData[0];
    // Persist the selected track in user storage
    if (conv.user.storage.track) {
        conv.user.storage.track = parseInt(conv.user.storage.track, 10);
        conv.user.storage.track++;
        if (conv.user.storage.track > audioData.length) {
            // Loop the tracks
            conv.user.storage.track = 1;
        }
        track = audioData[conv.user.storage.track - 1];
    } else {
        conv.user.storage.track = 1;
    }

    let hasScreen = conv.surface.capabilities.has('actions.capability.SCREEN_OUTPUT')
    console.log(`Current news: ${util.inspect(track)}`)
    if (hasScreen) {
        conv.ask('Has screen')
        // Create a media response
        // https://developers.google.com/actions/assistant/responses#media_responses
        conv.ask(new MediaObject({
            name: track.name,
            url: track.titleLink,
            icon: new Image({
                url: 'https://storage.googleapis.com/automotive-media/album_art.jpg',
                alt: 'Media icon'
            })
        }));
        // Add suggestions to continue the conversation
        if (supportsMore) {
            // Set the context to allow matching agent intents
            conv.contexts.set('more', 5);
            conv.ask(conv.user.storage.track === 1 ? suggestions1 : suggestions2);
        } else {
            conv.ask(suggestions3);
        }
    } else {
        conv.ask('There is no screen')
        // Create a media response
        // https://developers.google.com/actions/assistant/responses#media_responses
        conv.ask(new MediaObject({
            name: track.name,
            url: track.titleLink
        }));
    }
};

1 个答案:

答案 0 :(得分:1)

由于第三方开发人员无法提供存在另一个或上一个曲目的元数据,因此这些按钮始终处于禁用状态。开发人员在其Action中建立媒体响应时,应该会期待这种行为,因为它是API的当前状态。