From d830f44c55b2c68f3e397d35978adf3647a77b49 Mon Sep 17 00:00:00 2001 From: Nolan Darilek Date: Wed, 17 Jun 2020 18:54:34 -0500 Subject: [PATCH] Handle corner case where WinRT speech that doesn't interrupt, and is played after a delay, causes recently-spoken utterances to replay. `MediaPlayer` only seems to have states for playing and paused, but not stopped. Further, playing when the queue is finished seems to restart playback from the beginning. Here we clear the list of items to play if the player is paused and we're on the last item. We assume we're done with all items to speak, and clear the list before appending a new item and beginning playback again. The correct solution is probably to investigate how events work in winrt-rs, but callbacks and Rust have always been a disaster when I've tried them, so I'm hesitant. This does seem to handle the basic scenarios I've thrown at it. --- src/backends/winrt.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/backends/winrt.rs b/src/backends/winrt.rs index f250f1b..fa33458 100644 --- a/src/backends/winrt.rs +++ b/src/backends/winrt.rs @@ -56,6 +56,14 @@ impl Backend for WinRT { let content_type = stream.content_type()?; let source = MediaSource::create_from_stream(stream, content_type)?; let item = MediaPlaybackItem::create(source)?; + let state = self.player.playback_session()?.playback_state()?; + if state == MediaPlaybackState::Paused { + let index = self.playback_list.current_item_index()?; + let total = self.playback_list.items()?.size()?; + if index == total - 1 { + self.playback_list.items()?.clear()?; + } + } self.playback_list.items()?.append(item)?; if !self.is_speaking()? { self.player.play()?;