Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot get audioplayer state to do things like pause playback #54

Closed
rvanderwerf opened this issue Jul 16, 2017 · 2 comments
Closed

Cannot get audioplayer state to do things like pause playback #54

rvanderwerf opened this issue Jul 16, 2017 · 2 comments

Comments

@rvanderwerf
Copy link

So using the 1.4.0 new version of the sdk, I can't seem to get audioplayer state if I make an intent called pausePlayback - I need the audio player state to find out where the current playback is in ms to store where they were at, so you can resume from that point.
There weren't any example but I was able to glean what should work like so:
private AudioPlayerState getAudioPlayerState(Context context) {
def playerState = context.getState(AudioPlayerInterface.class, AudioPlayerState.class)
log.debug("playerState=${playerState)}")
return playerState
}

So calling this from onIntent with the requestenvelope context. Is this the right way to get this state? I know this state is passed in because I have a working fork of the sdk where I read that information and I can access it. To get an audio skill certified you must support the pause and resume playback functions so a user would need this to work.

@pavlo
Copy link

pavlo commented Nov 11, 2017

For me it would be natural to get the current playback position in onPlaybackStopped whose envelope has offsetInMilliseconds inside of PlaybackStoppedRequest. It however did not work for me the session is NULL in onPlaybackStopped so I can not persist the offset for the user because I there's no user/id in onPlaybackStopped. It is very confusing if I do not miss something extremely obvious...

Guys, could you please describe the recommended way to get playback offset in order to persist it for the user?

Thanks!

@ghost
Copy link

ghost commented Mar 30, 2018

Hey there,

In our 2.0.x major version of SDK, you can access them through AudioPlayer interface with a method called 'getOffsetInMilliseconds()'. This is my implementation of PauseIntentHandler when I was writing an audioplayer skill that handles AMAZON.PauseIntent.

public class PauseIntentHandler implements RequestHandler {
    @Override
    public boolean canHandle(HandlerInput input) {
        return input.matches(intentName("AMAZON.PauseIntent"));
    }

    @Override
    public Optional<Response> handle(HandlerInput input) {
        input.getAttributesManager().getPersistentAttributes().put("offset", input.getRequestEnvelope().getContext().getAudioPlayer().getOffsetInMilliseconds());
        input.getAttributesManager().savePersistentAttributes();

        return input.getResponseBuilder()
                .addAudioPlayerStopDirective()
                .withShouldEndSession(true)
                .build();
    }
}

Hope this helps!

@ghost ghost closed this as completed Mar 30, 2018
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants