From 45c7b1afc7606584e444a5c736febf19df38dc36 Mon Sep 17 00:00:00 2001 From: Nolan Darilek Date: Wed, 17 Jun 2020 16:46:42 -0500 Subject: [PATCH] Various WinRT refinements. * Move autogenerated code to subcrate to speed up compilation. * `is_speaking` also checks whether a source is opening, in addition to whether it is playing. * Return to using autoplay. --- Cargo.toml | 1 + src/backends/winrt.rs | 21 ++++++--------------- winrt_bindings/Cargo.toml | 11 +++++++++++ winrt_bindings/build.rs | 12 ++++++++++++ winrt_bindings/src/lib.rs | 1 + 5 files changed, 31 insertions(+), 15 deletions(-) create mode 100644 winrt_bindings/Cargo.toml create mode 100644 winrt_bindings/build.rs create mode 100644 winrt_bindings/src/lib.rs diff --git a/Cargo.toml b/Cargo.toml index 8955ede..99059fe 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,6 +18,7 @@ env_logger = "0.7" [target.'cfg(windows)'.dependencies] tolk = "0.2" winrt = "0.7" +winrt_bindings = {path="winrt_bindings"} [target.'cfg(target_os = "linux")'.dependencies] speech-dispatcher = "0.4" diff --git a/src/backends/winrt.rs b/src/backends/winrt.rs index 687713f..0009622 100644 --- a/src/backends/winrt.rs +++ b/src/backends/winrt.rs @@ -1,21 +1,11 @@ #[cfg(windows)] -use winrt::*; - -import!( - dependencies - os - types - windows::media::core::MediaSource - windows::media::playback::{MediaPlaybackItem, MediaPlaybackList, MediaPlaybackState, MediaPlayer} - windows::media::speech_synthesis::SpeechSynthesizer -); - use log::{info, trace}; -use windows::media::core::MediaSource; -use windows::media::playback::{ + +use winrt_bindings::windows::media::core::MediaSource; +use winrt_bindings::windows::media::playback::{ MediaPlaybackItem, MediaPlaybackList, MediaPlaybackState, MediaPlayer, }; -use windows::media::speech_synthesis::SpeechSynthesizer; +use winrt_bindings::windows::media::speech_synthesis::SpeechSynthesizer; use crate::{Backend, Error, Features}; @@ -35,6 +25,7 @@ impl WinRT { pub fn new() -> std::result::Result { info!("Initializing WinRT backend"); let player = MediaPlayer::new()?; + player.set_auto_play(true)?; let playback_list = MediaPlaybackList::new()?; player.set_source(&playback_list)?; Ok(Self { @@ -147,7 +138,7 @@ impl Backend for WinRT { fn is_speaking(&self) -> std::result::Result { let state = self.player.playback_session()?.playback_state()?; - let playing = state == MediaPlaybackState::Playing; + let playing = state == MediaPlaybackState::Opening || state == MediaPlaybackState::Playing; Ok(playing) } } diff --git a/winrt_bindings/Cargo.toml b/winrt_bindings/Cargo.toml new file mode 100644 index 0000000..943a50d --- /dev/null +++ b/winrt_bindings/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "winrt_bindings" +version = "0.1.0" +authors = ["Nolan Darilek "] +edition = "2018" + +[dependencies] +winrt = "0.7" + +[build-dependencies] +winrt = "0.7" diff --git a/winrt_bindings/build.rs b/winrt_bindings/build.rs new file mode 100644 index 0000000..9a1eb63 --- /dev/null +++ b/winrt_bindings/build.rs @@ -0,0 +1,12 @@ +winrt::build!( + dependencies + os + types + windows::media::core::MediaSource + windows::media::playback::{MediaPlaybackItem, MediaPlaybackList, MediaPlaybackState, MediaPlayer} + windows::media::speech_synthesis::SpeechSynthesizer +); + +fn main() { + build(); +} diff --git a/winrt_bindings/src/lib.rs b/winrt_bindings/src/lib.rs new file mode 100644 index 0000000..056780e --- /dev/null +++ b/winrt_bindings/src/lib.rs @@ -0,0 +1 @@ +include!(concat!(env!("OUT_DIR"), "/winrt.rs"));