Barbadoss
Barbadoss

Reputation: 1156

PlaybackNearlyFinished and PlaybackFinished occur almost at the same time?

It turns out, that sometimes (not always btw but very frequently) PlaybackNearlyFinished and PlaybackFinished occur almost at the same time. What also confuses is that both of the events convey exactly the same offset that represents the very end of the stream:

enter image description here

When this happens the next stream scheduled in PlaybackNearlyFinished does not go - the playback just finishes.

Unless this is a bug in Alexa/Infrastructure, I can not figure out how to implement a playback for a playlist - there's just no way to reliably schedule the upcoming track...

Is there anything I could do in my code to make it work well?

I am using Echo Dot 2 gen., physically located in Europe, use java SDK, AWS Lambda, Dynamo DB.

Upvotes: 1

Views: 166

Answers (1)

Barbadoss
Barbadoss

Reputation: 1156

Looks like it is figured out now - in order to queue the next stream properly one needs to come up with really unique stream tokens. This means that even the same file/url should be enqueued under a unique token.

In my example above, I used the index of the track in the playlist as an token. Once I solved it like below, everything started to work like a charm:

import org.apache.commons.lang3.RandomStringUtils;

public class TokenService {

    public String createToken(int playbackPosition) {
        String suffix = RandomStringUtils.randomAlphanumeric(16);
        return String.valueOf(playbackPosition) + ":" + suffix;
    }

    public int tokenToPlaybackIndex(String token) {
        String positionStr = token.split(":")[0];
        return Integer.valueOf(positionStr);
    }
}

Hope it helps somebody!

Upvotes: 2

Related Questions