Skip to content

Instantly share code, notes, and snippets.

@kinisoftware
Created April 11, 2021 15:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kinisoftware/0e6a219ffec67bd44b1e8c9d2d198d06 to your computer and use it in GitHub Desktop.
Save kinisoftware/0e6a219ffec67bd44b1e8c9d2d198d06 to your computer and use it in GitHub Desktop.
class PlaybackStoppedHandler : RequestHandler {
override fun canHandle(input: HandlerInput) =
input.matches(Predicates.requestType(PlaybackStoppedRequest::class.java))
override fun handle(input: HandlerInput): Optional<Response> {
val request = input.requestEnvelope.request
val intentRequest = request as PlaybackStoppedRequest
val lastPlayedAudio = JacksonSerializer().deserialize(
input.attributesManager.persistentAttributes["lastPlayedAudio"] as String,
Audio::class.java
)
input.attributesManager.persistentAttributes["lastPlayedAudio"] =
JacksonSerializer().serialize(
lastPlayedAudio.copy(lastPlayedOffsetInMilliseconds = intentRequest.offsetInMilliseconds)
)
input.attributesManager.savePersistentAttributes()
return input.responseBuilder.build()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment