pub struct FilePlayer { /* private fields */ }Expand description
An NDI source that plays recordings.
The source is advertised from creation until the player is dropped, whether
or not a file is playing; stop ends the current file only,
so receivers stay connected between files. Dropping the player stops
playback and removes the source.
A player belongs to the thread that created it, so it is neither Send
nor Sync: the File API documents no thread on which a player may be
used or destroyed, nor whether two calls on one player may overlap. Every
method calls into the SDK and may block.
AsyncFilePlayer offers the same operations as
futures.
Implementations§
Source§impl FilePlayer
impl FilePlayer
Sourcepub fn new(api: &FileApi, options: &FilePlayerOptions) -> Result<Self>
pub fn new(api: &FileApi, options: &FilePlayerOptions) -> Result<Self>
Create a player and advertise its NDI source.
The source is advertised from this call until the player is dropped, whether or not a file is playing. The options are only read, so they stay with the caller whatever the outcome.
§Errors
Error::InvalidInput when the player’s name or group list is empty,
or a group is empty or contains a comma or NUL. Error::InvalidCString when
the player’s name contains a NUL.
Error::NativeOperationFailed when the SDK cannot create the player
and Error::UnsupportedCapability when the library does not provide
FileFamily::Playback.
Sourcepub fn probe(api: &FileApi, path: impl AsRef<Path>) -> Result<FileInfo>
pub fn probe(api: &FileApi, path: impl AsRef<Path>) -> Result<FileInfo>
Read a recording’s duration and track layout.
Nothing is played and no NDI source is advertised.
An unreadable format payload does not discard the other information;
FileInfo::source_format reports the typed cause instead.
§Errors
Error::NativeOperationFailed when the SDK cannot read the file,
Error::InvalidInput when the path is empty or is not UTF-8,
Error::InvalidCString when it contains a NUL, Error::Io when a
relative path cannot be resolved because the current directory is
unavailable, and Error::UnsupportedCapability when the library
does not provide FileFamily::Playback.
Error::UnexpectedSdkResult when the library’s file information
does not match this crate’s structure layout.
Sourcepub fn start(&mut self, path: impl AsRef<Path>) -> Result<()>
pub fn start(&mut self, path: impl AsRef<Path>) -> Result<()>
Play a file through the advertised source.
A file already playing is closed first. Playback always begins unpaused
and uses the player’s looping setting. As specified by
Processing.NDI.Lib.File.Player.h, only the player’s first start may
wait up to about half a second, and only for a GOP-compressed file with
a receiver that has just connected, so it gets the opening keyframe.
There is no wait without a connected receiver, and later starts on the
same player never wait.
§Errors
Error::NativeOperationFailed when the SDK cannot open the file,
Error::InvalidInput when the path is empty or is not UTF-8,
Error::InvalidCString when it contains a NUL, and Error::Io when
a relative path cannot be resolved because the current directory is
unavailable.
Sourcepub fn is_running(&self) -> bool
pub fn is_running(&self) -> bool
Whether a file is playing. False after stop and once
playback reaches the end of a file that does not loop.
Sourcepub fn next_event(&mut self, timeout: Duration) -> Result<Option<PlayerEvent>>
pub fn next_event(&mut self, timeout: Duration) -> Result<Option<PlayerEvent>>
Take the next queued event, waiting up to timeout for one, or
None when none arrives in time.
An unreadable format is withheld through PlayerEvent::source_format
while the rest of the event is delivered.
§Errors
Error::InvalidInput when timeout exceeds crate::MAX_TIMEOUT,
and Error::UnexpectedSdkResult when the SDK’s event does not match
this crate’s structure layout or its returned event type.
Sourcepub fn dropped_event_count(&self) -> u64
pub fn dropped_event_count(&self) -> u64
How many events the SDK has discarded since the player was created because they were not taken in time.
Sourcepub fn stats(&self) -> Result<Option<PlayerStats>>
pub fn stats(&self) -> Result<Option<PlayerStats>>
Counters for the current or most recent file, when the SDK has any. Interpret them alongside playback session state and events, rather than as receiver-media progress.
§Errors
Error::UnexpectedSdkResult when the SDK’s structure does not match this
crate’s layout.
Sourcepub fn seek(&mut self, position: FilePosition) -> Result<()>
pub fn seek(&mut self, position: FilePosition) -> Result<()>
Seek to a position on the file’s timeline, where zero is its first frame.
GOP-compressed video resumes at the keyframe at or before the position; intra-only video resumes at the first frame at or after it.
§Errors
Error::NativeOperationFailed when the SDK refuses the seek.
Sourcepub fn seek_frame_approximate(&mut self, frame: u64) -> Result<()>
pub fn seek_frame_approximate(&mut self, frame: u64) -> Result<()>
Seek to a frame index.
The SDK converts the index to a time through the video frame rate, so the result is approximate for fractional rates.
§Errors
Error::NativeOperationFailed when the SDK refuses the seek.
Sourcepub fn set_paused(&mut self, paused: bool)
pub fn set_paused(&mut self, paused: bool)
Pause or resume the current file. Has no effect when no file is open.
Sourcepub fn is_paused(&self) -> bool
pub fn is_paused(&self) -> bool
Whether the current file is paused. Every start resets
this to false.
Sourcepub fn set_looping(&mut self, looping: bool)
pub fn set_looping(&mut self, looping: bool)
Set whether playback restarts at the end of a file.
Looping belongs to the player, not the file: it is kept across
start and stop. A looping file never
raises PlayerEventKind::Ended.
Sourcepub fn is_looping(&self) -> bool
pub fn is_looping(&self) -> bool
Whether playback restarts at the end of a file.
Sourcepub fn duration(&self) -> Option<FileDuration>
pub fn duration(&self) -> Option<FileDuration>
The current file’s best-known duration, and whether it is final.
A file that is still being recorded reports a provisional duration.
Sourcepub fn position(&self) -> Option<FilePosition>
pub fn position(&self) -> Option<FilePosition>
The position of the frame sent last: the main video track’s, or the audio track’s in a file without video.
Sourcepub fn source_timecode(&self) -> Option<Timecode>
pub fn source_timecode(&self) -> Option<Timecode>
The recorded source timecode of the frame sent last. Unlike the position it is editorial and need not increase.
Sourcepub fn source_format(&self) -> Result<Option<SourceFormat>>
pub fn source_format(&self) -> Result<Option<SourceFormat>>
The track layout of the current file, once one with audio or video is open. A known layout alone does not establish current playback progress; inspect the player state and events as well.
§Errors
Error::UnexpectedSdkResult when the SDK’s structure is malformed.
Sourcepub fn advertised_source(&self) -> Result<Source>
pub fn advertised_source(&self) -> Result<Source>
The NDI source this player advertises, for example to connect a
Receiver to it.
§Errors
Error::NativeOperationFailed when the SDK returns no source, or one
that names neither a source nor an address, and
Error::UnexpectedSdkResult when its name or address is longer than
the 4 MiB available for one SDK string, including its terminator.
Error::InvalidUtf8 reports an invalid name or address.
Error::AllocationFailed reports a failed text buffer reservation.
See crate::Finder::current_sources for allocation behavior of
shared source owners.