我通过使用MediaResponse
Media Player可以在两侧正确播放:
在Google simulator
Google Assistant
在手机上
然后
它可以在Google Assistant
上执行以下功能:
播放
暂停
停止
恢复
Simulator
无法做到这一点(作为图片,它总是再次询问我)
我想知道为什么吗?
认识的人,帮我解释一下吗?
p / s:
pause
和stop
之间有什么区别?
在Google助手上,我看到它们具有相同的功能,这意味着stop
与pause
完全相似。
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;
答案 0 :(得分:0)
代码正确。
但是目前正像文档所说的:Media responses are supported on Android phones and on Google Home