mirror of
https://github.com/RustAudio/rodio
synced 2024-12-13 21:52:38 +00:00
Change get_remaining_duration_ms to get_min_remaining_duration
This commit is contained in:
parent
e2fc982652
commit
d786f79e02
2 changed files with 8 additions and 6 deletions
|
@ -2,6 +2,7 @@ use std::cmp;
|
|||
use std::mem;
|
||||
use std::collections::HashMap;
|
||||
use std::thread::{self, Builder, Thread};
|
||||
use std::time::Duration;
|
||||
use std::sync::mpsc::{self, Sender, Receiver};
|
||||
use std::sync::atomic::AtomicUsize;
|
||||
use std::sync::atomic::Ordering;
|
||||
|
@ -175,8 +176,8 @@ impl<'a> Handle<'a> {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pub fn get_remaining_duration_ms(&self) -> u32 {
|
||||
self.remaining_duration_ms.load(Ordering::Relaxed) as u32
|
||||
pub fn get_min_remaining_duration(&self) -> Duration {
|
||||
Duration::from_millis(self.remaining_duration_ms.load(Ordering::Relaxed) as u64)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@ pub use decoder::Decoder;
|
|||
pub use source::Source;
|
||||
|
||||
use std::io::{Read, Seek};
|
||||
use std::time::Duration;
|
||||
use std::thread;
|
||||
|
||||
mod conversions;
|
||||
|
@ -58,19 +59,19 @@ impl Sink {
|
|||
self.0.stop()
|
||||
}
|
||||
|
||||
/// Returns the minimum number of milliseconds remaining before the end of the sound.
|
||||
/// Returns the minimum duration before the end of the sounds submitted to this sink.
|
||||
///
|
||||
/// Note that this is a minimum value, and the sound can last longer.
|
||||
#[inline]
|
||||
pub fn get_remaining_duration_ms(&self) -> u32 {
|
||||
self.0.get_remaining_duration_ms()
|
||||
pub fn get_min_remaining_duration(&self) -> Duration {
|
||||
self.0.get_min_remaining_duration()
|
||||
}
|
||||
|
||||
/// Sleeps the current thread until the sound ends.
|
||||
#[inline]
|
||||
pub fn sleep_until_end(&self) {
|
||||
// TODO: sleep repeatidely until the sound is finished (see the docs of `get_remaining_duration`)
|
||||
thread::sleep_ms(self.get_remaining_duration_ms());
|
||||
thread::sleep(self.get_min_remaining_duration());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue