pub struct AsyncSCRecordingOutput { /* private fields */ }Expand description
Async wrapper for SCRecordingOutput with event stream (macOS 15.0+)
Provides async iteration over recording lifecycle events. Executor-agnostic - works with any async runtime.
§Examples
use screencapturekit::async_api::{AsyncSCShareableContent, AsyncSCRecordingOutput, RecordingEvent};
use screencapturekit::recording_output::SCRecordingOutputConfiguration;
use screencapturekit::stream::{SCStream, configuration::SCStreamConfiguration, content_filter::SCContentFilter};
use std::path::Path;
async fn record_screen() -> Option<()> {
let content = AsyncSCShareableContent::get().await.ok()?;
let displays = content.displays();
let display = displays.first()?;
let filter = SCContentFilter::create().with_display(display).with_excluding_windows(&[]).build();
let config = SCStreamConfiguration::new().with_width(1920).with_height(1080);
let rec_config = SCRecordingOutputConfiguration::new()
.with_output_url(Path::new("/tmp/recording.mp4"));
let (recording, events) = AsyncSCRecordingOutput::new(&rec_config)?;
let mut stream = SCStream::new(&filter, &config);
stream.add_recording_output(&recording).ok()?;
stream.start_capture().ok()?;
// Wait for recording events
while let Some(event) = events.next().await {
match event {
RecordingEvent::Started => println!("Recording started!"),
RecordingEvent::Finished => {
println!("Recording finished!");
break;
}
RecordingEvent::Failed(e) => {
eprintln!("Recording failed: {}", e);
break;
}
}
}
Some(())
}Implementations§
Source§impl AsyncSCRecordingOutput
impl AsyncSCRecordingOutput
Sourcepub fn new(
config: &SCRecordingOutputConfiguration,
) -> Option<(SCRecordingOutput, Self)>
pub fn new( config: &SCRecordingOutputConfiguration, ) -> Option<(SCRecordingOutput, Self)>
Create a new async recording output
Returns a tuple of (SCRecordingOutput, AsyncSCRecordingOutput).
The SCRecordingOutput should be added to an SCStream, while
the AsyncSCRecordingOutput provides async event iteration.
§Errors
Returns None if the recording output cannot be created (requires macOS 15.0+).
Sourcepub fn next(&self) -> NextRecordingEvent<'_> ⓘ
pub fn next(&self) -> NextRecordingEvent<'_> ⓘ
Get the next recording event asynchronously
Returns None when the recording has finished or failed.
Sourcepub fn is_finished(&self) -> bool
pub fn is_finished(&self) -> bool
Check if the recording has finished
Sourcepub fn try_next(&self) -> Option<RecordingEvent>
pub fn try_next(&self) -> Option<RecordingEvent>
Get any pending events without waiting
Trait Implementations§
Auto Trait Implementations§
impl Freeze for AsyncSCRecordingOutput
impl RefUnwindSafe for AsyncSCRecordingOutput
impl Send for AsyncSCRecordingOutput
impl Sync for AsyncSCRecordingOutput
impl Unpin for AsyncSCRecordingOutput
impl UnwindSafe for AsyncSCRecordingOutput
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more