AsyncSCRecordingOutput

Struct AsyncSCRecordingOutput 

Source
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

Source

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+).

Source

pub fn next(&self) -> NextRecordingEvent<'_>

Get the next recording event asynchronously

Returns None when the recording has finished or failed.

Source

pub fn is_finished(&self) -> bool

Check if the recording has finished

Source

pub fn try_next(&self) -> Option<RecordingEvent>

Get any pending events without waiting

Trait Implementations§

Source§

impl Debug for AsyncSCRecordingOutput

Available on crate feature macos_15_0 only.
Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.