alexa-samples / skill-sample-nodejs-audio-player

An Alexa Skill Sample showing how to play long form audio in 3P-skills
Other
470 stars 319 forks source link

`PlaybackFinished` fired before `PlaybackNearlyFinished` #37

Closed rpastorelle closed 6 years ago

rpastorelle commented 7 years ago

I've consistently noticed when using audio clips <1m in length (e.g. 30s long clips) that AudioPlayer events are fired out of order, in an unreliable manner.

This compromises the integrity of the code in this example because it assumes that "NearlyFinished" will fire before "Finished" is fired.

Here's my log output:

18:17:15    PlaybackStarted for token 0-0
18:17:47    PlaybackFinished for token 0-0
18:17:48    PlaybackNearlyFinished for token 0-0 / Queueing token 0-1
18:17:49    PlaybackStarted for token 0-1
18:18:20    PlaybackNearlyFinished for token 0-1
18:18:20    PlaybackFinished for token 0-1
stevefulton commented 7 years ago

What device are you seeing the come from? I get consistent events from a Dot, but the Show and Echo do not appear to fire the events at the right time.

tkang commented 7 years ago

Here is what I've observed on when PlaybackNearlyFinished event gets fired, as of today.

So they all fire same events at different times :-(

I also enqueue next music on PlaybackNearlyFinished event so next music gets automatically played after current one. Sadly in Echo Dot's case, this doesn't work since there is very little time window between PlaybackNearlyFinished and PlaybackFinished. My guess is PlaybackFinished event gets fired before enqueuing next music request is done (e.g. directive being { type: AudioPlayer.Play, playBehavior: "ENQUEUE"})

allthepies commented 7 years ago

I'm seeing the same behavior as tkang for the Dot case, as in PlaybackNearlyFinished event arrives very close (prior) to PlaybackFinished. I ENQUEUE upon receipt of a PlaybackNearlyFinished event. This works about 50% of the time, for the other 50% the next track doesn't start playing. It is being enqueued though as if I ask Alexa for the time / weather / whatever then when she's given me that information then the enqueued track starts playing. So I suspect that there's a race condition in the Amazon AudioPlayer for ENQUEUE requests received after/around the same time as a PlaybackFinished event has been generated.

I have no option than to stop using the ENQUEUE capability and will have to play the next track upon receipt of a PlaybackFinished event. Unless anyone else has suggestions ? Edit: Can't do this as tracks can't be played in response to PlaybackFinished events.

All my testing /experience of this issue is on Dot devices BTW.

rossthedevigner commented 6 years ago

I can confirm this as well. My enqueued audio will not play even with really unique tokens.

allthepies commented 6 years ago

FWIW My skills are now working reliably using unique tokens. I append a GUID to the numeric index value which was previously being used (with a colon separator) when I generate the token. And strip off the GUID when I receive a token in an audio player event.

talkingnews commented 6 years ago

Hey @allthepies , that sounds like great news BUT... I'm not entirely sure how you're doing that. In fact, information about the purpose/use of audio tokens seems to a bit lacking in general. Any chance of a quick bit of code, or an little expansion on the info?

sebsto commented 6 years ago

AudioPlayer Play directive documentation has a good documentation on token and how it used to prevent race conditions. https://developer.amazon.com/docs/custom-skills/audioplayer-interface-reference.html#play Generating unique tokens for track is indeed a best practice. Does that answer the question ?