I'm developing a skill which streams audio files. Playback is working fine, even pause, resume and "getNextSong" is working, but i can't enqueue a song after the first one finishes.
@Override public SpeechletResponse onPlaybackNearlyFinished(SpeechletRequestEnvelope<PlaybackNearlyFinishedRequest> requestEnvelope) { logger.info("Playback nearly finished"); return queueNextSong(requestEnvelope); }
Enqueue method:
private SpeechletResponse queueNextSong(SpeechletRequestEnvelope<PlaybackNearlyFinishedRequest> requestEnvelope) { SystemState state = requestEnvelope.getContext().getState(SystemInterface.class, SystemState.class); logger.info("Queue next song"); UserSession userSession = null; try { userSession = new DynamoDbService().getUserSession(state.getUser().getUserId()); } catch (Exception e) { logger.error("Unable to obtain userSession Object."); } logger.info("User session obtained"); 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); logger.info("Return enqueue response"); return response; }
What am i missing? I need some help please... i have read the official documentation and checked the forum here but none of the solutions are working. :(