媒体播放器在模拟器上无法在Google Assistant上正常播放

时间:2018-11-14 02:41:10

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

我通过使用MediaResponse

在AOG上实现了简单媒体播放器

Media Player可以在两侧正确播放:

  • 在Google simulator

  • 上的操作
  • Google Assistant在手机上

然后

它可以在Google Assistant上执行以下功能:

  • 播放

  • 暂停

  • 停止

  • 恢复

Simulator无法做到这一点(作为图片,它总是再次询问我)

我想知道为什么吗?

认识的人,帮我解释一下吗?

p / s:

pausestop之间有什么区别?

在Google助手上,我看到它们具有相同的功能,这意味着stoppause完全相似。

enter image description here

enter image description here

MediaPlayerUtils.js

// Library
const {
MediaObject,
MediaResponse,
SimpleResponse,
Suggestions
} = require('actions-on-google');

class MediaPlayerUtils {

getMediaResponse(song) {
    // This object used to play Media on Google Home
    var mediaResponse = new MediaResponse();
    mediaResponse.mediaType = "AUDIO";

    var mediaObject = new MediaObject({
        url: ""
    });

    mediaObject.name = song.title;
    mediaObject.contentUrl = song.url;

    mediaResponse.mediaObjects = [];
    mediaResponse.mediaObjects.push(mediaObject);

    var Media = require('../model/data/Media');

    // Media Response : Play audio
    return new Media(song, mediaResponse);
}

playSong(conv, song) {
    var media = require('../model/data/Media');
    media = this.getMediaResponse(song);

    console.log("playSong() " + song.title + " " + song.url);

    // Media Response : Play audio
    conv.ask(new SimpleResponse(" ")); // Able to set song title before playing song in here
    conv.ask(media.mediaResponse);
    conv.ask(new Suggestions(
        "next",
        "back",
        "previous",
        "play",
        "pause",
        "resume",
        "stop"));
    conv.ask(new SimpleResponse(""));
};

}

module.exports = MediaPlayerUtils;

routes.js

'use strict';


const {
dialogflow
} = require('actions-on-google');

const assistant = dialogflow({ debug: true });

const MediaPlayerUtils = require('./util/MediaPlayerUtils');
const mediaPlayer = new MediaPlayerUtils();

module.exports = function (app) {

assistant.intent('Default Fallback Intent', (conv) => {
    conv.close("Goodbye");
});

assistant.intent('Default Welcome Intent', (conv) => {
    var song = {
        title: "Test",
        url: "https://TEST_URL.mp3"
    };

    console.log("Default Welcome Intent");

    mediaPlayer.playSong(conv, song);
});

module.exports.googleHomeActions = assistant;

app.post('/webhook', assistant);
};

Media.js

var Media = function (song, mediaResponse) {
this.song = song;
this.mediaResponse = mediaResponse;
}

module.exports = Media;

1 个答案:

答案 0 :(得分:0)

代码正确。

但是目前正像文档所说的:Media responses are supported on Android phones and on Google Home