Search code examples
node.jsactions-on-googlegoogle-home

How to enable next button of music actions in google home hub


I am developing a music action. I use MediaObject to return and play audio. When I try actions on google home hub, at the bottom of the screen has 2 buttons for next and previous. Although there are more audio and I can say 'Next' for another audio, both of the buttons are disabled. How can I enable it? Thanks in advance!

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
        }));
    }
};


Solution

  • The buttons are always disabled, as third-party developers are unable to provide metadata that there is another or previous track. Developers building a media response in their Action should expect this behavior, as it's the current state of the API.