Expand description
§avplayer
Safe Rust bindings for Apple’s AVPlayer, AVPlayerItem, AVAsset, AVURLAsset, and AVAssetReader on macOS.
Status:
0.1.0covers practical playback + inspection workflows: URL/file assets, asynchronous key loading, track + metadata listing, basic AVPlayer control,AVPlayerItemobservation, time observers, and frame/sample reading throughAVAssetReaderoutputs.
§Quick start
use avplayer::prelude::*;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let asset = UrlAsset::from_file_path("target/example-artifacts/test.aiff")?;
asset.load_values_asynchronously(["duration", "tracks", "metadata"])?;
println!("duration: {:?}", asset.duration()?);
println!("tracks: {}", asset.tracks()?.len());
let player = Player::from_asset(asset.as_asset())?;
println!("status: {:?}", player.status()?);
player.play();
player.pause();
Ok(())
}§Highlights
UrlAsset::from_file_path/UrlAsset::from_remote_urlAsset::load_values_asynchronously,status_of_value,duration,tracks,metadataPlayer::from_url,Player::from_asset,play,pause,rate,seek_to,current_time,durationPlayerItem::observefor status / presentation-size / end-of-playback eventsPlayer::add_periodic_time_observer/add_boundary_time_observerAssetReader,AssetReaderTrackOutput,AssetReaderAudioMixOutput,AssetReaderVideoCompositionOutputVideoOutputSettings+AudioOutputSettingshelpers forAVAssetReaderconversion dictionariesapple-cfinterop forCMSampleBufferandCVPixelBuffer
§Smoke example
cargo run --all-features --example 01_smoke_surfaceThe smoke example synthesizes a short AIFF under target/example-artifacts/, loads it as an AVURLAsset, inspects metadata/tracks, reads the first sample buffers through AVAssetReader, and exercises AVPlayer control + observer registration.
§Notes
AVPlayerLayeris intentionally out of scope for this crate; it belongs to AppKit/UIKit presentation layers.- The current macOS SDK used for this release does not expose an
AVPlayerItem.externalMetadataproperty, soPlayerItem::metadata()returns the underlying asset metadata instead.
§License
Licensed under either of Apache-2.0 or MIT at your option.
Modules§
Structs§
- Asset
- Safe wrapper around
AVAsset. - Asset
Reader - Safe wrapper around
AVAssetReader. - Asset
Reader Audio MixOutput AVAssetReaderAudioMixOutput.- Asset
Reader Track Output AVAssetReaderTrackOutput.- Asset
Reader Video Composition Output AVAssetReaderVideoCompositionOutput.- Asset
Track - Safe wrapper around
AVAssetTrack. - Audio
Output Settings - Builder for linear-PCM audio
AVAssetReaderoutput settings. - Boundary
Time Observer - RAII token for
addBoundaryTimeObserver. - KeyLoad
Status - Result for a single key passed to
load_values_asynchronously. - Metadata
Item - Simplified
AVMetadataItemview suitable for asset/player inspection. - Periodic
Time Observer - RAII token for
addPeriodicTimeObserver. - Player
- Safe wrapper around
AVPlayer. - Player
Item - Safe wrapper around
AVPlayerItem. - Player
Item Observer - KVO + notification observer for
AVPlayerItem. - Size
- Serializable
CGSizemirror. - Time
Range - Serializable representation of
CMTimeRange. - UrlAsset
AVURLAssetconvenience wrapper aroundAsset.- Video
Output Settings - Builder for uncompressed video
AVAssetReaderoutput settings.
Enums§
- AVPlayer
Error - Top-level error type returned by fallible APIs in this crate.
- Asset
Reader Status AVAssetReaderStatus.- KeyValue
Status - Per-key loading state returned by
AVAsynchronousKeyValueLoading. - Media
Type - Simplified media-type classification for asset tracks and reader outputs.
- Player
Item Event - Events emitted by
PlayerItemObserver. - Player
Item Status AVPlayerItemStatus.- Player
Status AVPlayerStatus.- Time
- Serializable representation of
CMTime.