adds try_seek to spatial source

This commit is contained in:
dvdsk 2023-10-10 13:37:28 +02:00
parent f3a1966348
commit 560961fc8b
No known key found for this signature in database
GPG key ID: 6CF9D20C5709A836

View file

@ -4,7 +4,7 @@ use std::time::Duration;
use cpal::FromSample;
use crate::source::Spatial;
use crate::source::{Spatial, SeekError};
use crate::stream::{OutputStreamHandle, PlayError};
use crate::{Sample, Sink, Source};
@ -164,4 +164,28 @@ impl SpatialSink {
pub fn len(&self) -> usize {
self.sink.len()
}
/// Attempts to seek to a given position in the current source.
///
/// This blocks between 0 and ~5 milliseconds.
///
/// As long as the *duration of the source is known* seeking saturates. This means
/// when you try to seek beyong the length of the source this function will seek
/// to the end of the source instead.
///
/// If the duration of the source is known and the seek position lies beyond
/// it the saturates, that is the position is then at the end of the source.
///
/// # Errors
/// This function will return [`SeekError::NotSupported`] if one of the underlying
/// sources does not support seeking.
///
/// It will return an error if an implementation ran
/// into one during the seek.
///
/// When seeking beyond the end of a source this
/// function might return an error if the duration of the source is not known.
pub fn try_seek(&self, pos: Duration) -> Result<(), SeekError> {
self.sink.try_seek(pos)
}
}