Skip to main content

Crate avplayer

Crate avplayer 

Source
Expand description

§avplayer

Safe Rust bindings for Apple’s AVPlayer, AVPlayerItem, AVAsset, AVURLAsset, and AVAssetReader on macOS.

Status: 0.1.0 covers practical playback + inspection workflows: URL/file assets, asynchronous key loading, track + metadata listing, basic AVPlayer control, AVPlayerItem observation, time observers, and frame/sample reading through AVAssetReader outputs.

§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_url
  • Asset::load_values_asynchronously, status_of_value, duration, tracks, metadata
  • Player::from_url, Player::from_asset, play, pause, rate, seek_to, current_time, duration
  • PlayerItem::observe for status / presentation-size / end-of-playback events
  • Player::add_periodic_time_observer / add_boundary_time_observer
  • AssetReader, AssetReaderTrackOutput, AssetReaderAudioMixOutput, AssetReaderVideoCompositionOutput
  • VideoOutputSettings + AudioOutputSettings helpers for AVAssetReader conversion dictionaries
  • apple-cf interop for CMSampleBuffer and CVPixelBuffer

§Smoke example

cargo run --all-features --example 01_smoke_surface

The 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

  • AVPlayerLayer is 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.externalMetadata property, so PlayerItem::metadata() returns the underlying asset metadata instead.

§License

Licensed under either of Apache-2.0 or MIT at your option.

Modules§

ffi
Raw FFI declarations matching swift-bridge/Sources/AVPlayerBridge.
prelude
Common imports.

Structs§

Asset
Safe wrapper around AVAsset.
AssetReader
Safe wrapper around AVAssetReader.
AssetReaderAudioMixOutput
AVAssetReaderAudioMixOutput.
AssetReaderTrackOutput
AVAssetReaderTrackOutput.
AssetReaderVideoCompositionOutput
AVAssetReaderVideoCompositionOutput.
AssetTrack
Safe wrapper around AVAssetTrack.
AudioOutputSettings
Builder for linear-PCM audio AVAssetReader output settings.
BoundaryTimeObserver
RAII token for addBoundaryTimeObserver.
KeyLoadStatus
Result for a single key passed to load_values_asynchronously.
MetadataItem
Simplified AVMetadataItem view suitable for asset/player inspection.
PeriodicTimeObserver
RAII token for addPeriodicTimeObserver.
Player
Safe wrapper around AVPlayer.
PlayerItem
Safe wrapper around AVPlayerItem.
PlayerItemObserver
KVO + notification observer for AVPlayerItem.
Size
Serializable CGSize mirror.
TimeRange
Serializable representation of CMTimeRange.
UrlAsset
AVURLAsset convenience wrapper around Asset.
VideoOutputSettings
Builder for uncompressed video AVAssetReader output settings.

Enums§

AVPlayerError
Top-level error type returned by fallible APIs in this crate.
AssetReaderStatus
AVAssetReaderStatus.
KeyValueStatus
Per-key loading state returned by AVAsynchronousKeyValueLoading.
MediaType
Simplified media-type classification for asset tracks and reader outputs.
PlayerItemEvent
Events emitted by PlayerItemObserver.
PlayerItemStatus
AVPlayerItemStatus.
PlayerStatus
AVPlayerStatus.
Time
Serializable representation of CMTime.