我正在开发一种流式传输音频文件的Alexa技能。播放工作正常,甚至暂停,恢复和“getNextSong”正在工作,但我不能在第一个完成后排队。
这就是我调用我的方法来排队下一首歌的地方:
@Override
public SpeechletResponse onPlaybackNearlyFinished(SpeechletRequestEnvelope<PlaybackNearlyFinishedRequest> requestEnvelope) {
logger.info("Playback nearly finished");
return queueNextSong(requestEnvelope);
}
这是我的入队方法:
private SpeechletResponse queueNextSong(SpeechletRequestEnvelope<PlaybackNearlyFinishedRequest> requestEnvelope) {
SystemState state = requestEnvelope.getContext().getState(SystemInterface.class, SystemState.class);
UserSession userSession = null;
try {
userSession = new DynamoDbService().getUserSession(state.getUser().getUserId());
} catch (Exception e) {
logger.error("Unable to obtain userSession Object.");
}
String url = null;
// Don't worry about this line, i just use the last object of my songList because it's cheaper to remove than the first entry.
url = userSession.getSongQueue().get(userSession.getSongQueue().size()-1);
Stream stream = new Stream();
stream.setUrl(url);
stream.setOffsetInMilliseconds(0);
stream.setExpectedPreviousToken(requestEnvelope.getRequest().getToken());
stream.setToken(url);
AudioItem audioItem = new AudioItem();
audioItem.setStream(stream);
PlayDirective playDirective = new PlayDirective();
playDirective.setAudioItem(audioItem);
playDirective.setPlayBehavior(PlayBehavior.ENQUEUE);
List<Directive> directives = new ArrayList<>();
directives.add(playDirective);
SpeechletResponse response = new SpeechletResponse();
response.setDirectives(directives);
return response;
}
我缺少什么?我需要一些帮助...我已经阅读了官方文档并检查了论坛,但没有一个解决方案正在运行。 :(我回复了错误的回答吗?错字?感谢任何帮助。