Skip to main content

SCStreamDelegateTrait

Trait SCStreamDelegateTrait 

Source
pub trait SCStreamDelegateTrait: Send + Sync {
    // Provided methods
    fn output_video_effect_did_start_for_stream(&self) { ... }
    fn output_video_effect_did_stop_for_stream(&self) { ... }
    fn stream_did_become_active(&self) { ... }
    fn stream_did_become_inactive(&self) { ... }
    fn did_stop_with_error(&self, _error: SCError) { ... }
}
Expand description

Trait for handling stream lifecycle events

Implement this trait to receive notifications about stream state changes, errors, and video effects.

§Examples

§Using a struct

use screencapturekit::stream::delegate_trait::SCStreamDelegateTrait;
use screencapturekit::error::SCError;

struct MyDelegate;

impl SCStreamDelegateTrait for MyDelegate {
    fn did_stop_with_error(&self, error: SCError) {
        eprintln!("Stream stopped with error: {}", error);
    }
}

§Using closures

Use StreamCallbacks to create a delegate from closures:

use screencapturekit::prelude::*;
use screencapturekit::stream::delegate_trait::StreamCallbacks;


let delegate = StreamCallbacks::new()
    .on_stop(|error| {
        if let Some(e) = error {
            eprintln!("Stream stopped with error: {}", e);
        }
    })
    .on_error(|error| eprintln!("Error: {}", error));

let stream = SCStream::new_with_delegate(&filter, &config, delegate)?;

Provided Methods§

Source

fn output_video_effect_did_start_for_stream(&self)

Called when video effects start (macOS 14.0+)

Notifies when the stream’s overlay video effect (presenter overlay) has started.

Requires the macos_14_0 cargo feature: without it the bridge does not compile Apple’s outputVideoEffectDidStart(for:) and this never fires.

Source

fn output_video_effect_did_stop_for_stream(&self)

Called when video effects stop (macOS 14.0+)

Notifies when the stream’s overlay video effect (presenter overlay) has stopped.

Requires the macos_14_0 cargo feature — see output_video_effect_did_start_for_stream.

Source

fn stream_did_become_active(&self)

Called when the stream becomes active (macOS 15.2+)

Notifies the first time any window that was being shared in the stream is re-opened after all the windows being shared were closed. When all the windows being shared are closed, the client will receive stream_did_become_inactive.

Requires the macos_15_2 cargo feature: without it the bridge does not compile Apple’s streamDidBecomeActive(_:) and this never fires.

Source

fn stream_did_become_inactive(&self)

Called when the stream becomes inactive (macOS 15.2+)

Notifies when all the windows that are currently being shared are exited. This callback occurs for all content filter types.

Requires the macos_15_2 cargo feature — see stream_did_become_active.

Source

fn did_stop_with_error(&self, _error: SCError)

Called when the stream stops with an error.

This is the canonical stop notification and mirrors Apple’s stream(_:didStopWithError:) — the only way ScreenCaptureKit reports a stop to the delegate. It fires when the stream stops unexpectedly (the captured window/display goes away, screen-recording permission is revoked, the system tears the stream down, …).

A clean stop that you requested via SCStream::stop_capture is not reported here — observe it through that method’s return value.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§