24 lines
757 B
Rust
24 lines
757 B
Rust
use windows::{
|
|
core::{implement, Interface},
|
|
Win32::Media::Audio::{
|
|
IAudioSessionControl, IAudioSessionControl2, IAudioSessionNotification, IAudioSessionNotification_Impl,
|
|
},
|
|
};
|
|
|
|
#[implement(IAudioSessionNotification)]
|
|
pub(crate) struct SessionNotification {
|
|
pub(crate) observer: Box<dyn SessionObserver>,
|
|
}
|
|
|
|
pub trait SessionObserver {
|
|
fn add_session(&self, session: IAudioSessionControl2);
|
|
}
|
|
|
|
impl IAudioSessionNotification_Impl for SessionNotification_Impl {
|
|
fn OnSessionCreated(&self,newsession:windows_core::Ref<'_, IAudioSessionControl>) -> windows::core::Result<()> {
|
|
let ses: IAudioSessionControl2 = newsession.as_ref().unwrap().cast().unwrap();
|
|
self.observer.add_session(ses);
|
|
Ok(())
|
|
}
|
|
}
|