diff --git a/src/engine.rs b/src/engine.rs index eb371bb..5216340 100644 --- a/src/engine.rs +++ b/src/engine.rs @@ -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) } } diff --git a/src/lib.rs b/src/lib.rs index 6ca9018..011741a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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()); } }