Skip to content
This repository has been archived by the owner on May 6, 2022. It is now read-only.

Commit

Permalink
fix: don't send irrelevant playback events
Browse files Browse the repository at this point in the history
It appears that ExoPlayer can fire state change events for audio
from any source. This change prevents Spokestack PLAYBACK_COMPLETE
events from being dispatched unless the player was known to have
received audio from Spokestack when the state change event occurred.
  • Loading branch information
space-pope committed Sep 23, 2020
1 parent eada1bb commit 303cee9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,12 @@ MediaSource createMediaSource(Uri audioUri) {
@Override
public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
if (playbackState == Player.STATE_ENDED) {
resetPlayerState();
dispatch(new TTSEvent(TTSEvent.Type.PLAYBACK_COMPLETE));
// check for content produced by the TTS system; the player can
// also receive state change events for audio from another source
if (this.playerState.hasContent) {
dispatch(new TTSEvent(TTSEvent.Type.PLAYBACK_COMPLETE));
resetPlayerState();
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,13 @@ public void testPlayerStateChange() {

ttsOutput.onPlayerStateChanged(false, Player.STATE_ENDED);
assertFalse(ttsOutput.getPlayerState().hasContent);
// no playback_complete event if the player didn't have content from
// the TTS system
assertTrue(listener.events.isEmpty());

// now give it audio to play and check again
ttsOutput.audioReceived(new AudioResponse(Uri.EMPTY));
ttsOutput.onPlayerStateChanged(false, Player.STATE_ENDED);
assertEquals(1, listener.events.size());
assertEquals(TTSEvent.Type.PLAYBACK_COMPLETE,
listener.events.get(0).type);
Expand Down

0 comments on commit 303cee9

Please sign in to comment.