add a command to jump to an arbitrary time
[nihav-player.git] / sndplay / src / main.rs
index 66def2b05250b0fe3f3fe5a32aa330e12c3fafec..377c2d1b11bb7b134f3a1b9e1bd5ad287a61d175 100644 (file)
@@ -335,15 +335,18 @@ impl Player {
         if !self.paused {
             device.resume();
         }
+        let mut no_display = false;
         'main: loop {
             let cur_time = decoder.samplepos.saturating_sub(u64::from(device.size() / 2 / u32::from(dst_info.channels)));
             let full_ms = cur_time * 1000 / u64::from(arate);
             let timestr = format_time(full_ms);
             let disp_vol = if self.mute { 0 } else { self.volume };
-            if !self.debug {
-                print!("> {} / {}   {}%       \r", timestr, duration_str, disp_vol);
-            } else {
-                print!("> {} / {}   |{}| {}%       \r", timestr, duration_str, device.size(), disp_vol);
+            if !no_display {
+                if !self.debug {
+                    print!("> {} / {}   {}%       \r", timestr, duration_str, disp_vol);
+                } else {
+                    print!("> {} / {}   |{}| {}%       \r", timestr, duration_str, device.size(), disp_vol);
+                }
             }
             std::io::stdout().flush().unwrap();
             if device.size() < underfill_limit && !self.paused && refill_limit < (1 << 20) {
@@ -403,6 +406,20 @@ impl Player {
                             device.resume();
                         }
                     },
+                    Command::Seek(seek_time) => {
+                        device.pause();
+                        device.clear();
+                        let _ret = decoder.seek(seek_time);
+                        while !eof && device.size() < refill_limit {
+                            eof = decoder.refill(&device);
+                        }
+                        if eof {
+                            break 'main;
+                        }
+                        if !self.paused {
+                            device.resume();
+                        }
+                    },
                     Command::Quit => {
                         device.pause();
                         self.ended = true;
@@ -449,8 +466,12 @@ impl Player {
                     Command::Debug => {
                         self.debug = !self.debug;
                     },
+                    Command::PauseDisplay  => { no_display = true; },
+                    Command::ResumeDisplay => { no_display = false; },
                 };
-                print!("\r{:60}\r", ' ');
+                if !no_display {
+                    print!("\r{:60}\r", ' ');
+                }
             }
             thread::sleep(Duration::from_millis(200));
         }