]> git.nihav.org Git - nihav-player.git/commitdiff
sndplay: support -start option
authorKostya Shishkov <kostya.shishkov@gmail.com>
Mon, 4 Jan 2021 13:32:12 +0000 (14:32 +0100)
committerKostya Shishkov <kostya.shishkov@gmail.com>
Mon, 4 Jan 2021 13:32:12 +0000 (14:32 +0100)
sndplay/src/main.rs

index 176a6d189d8e55b3821ca9c747aa17513ad4b81d..43f8fca879895f016df669541c16c4d15ced5986 100644 (file)
@@ -228,7 +228,7 @@ impl Player {
             buf:    Vec::new(),
         }
     }
-    fn play_file(&mut self, name: &str, cmd_receiver: &mpsc::Receiver<Command>) {
+    fn play_file(&mut self, name: &str, cmd_receiver: &mpsc::Receiver<Command>, start_time: NATimePoint) {
         let ret = File::open(name);
         if ret.is_err() {
             println!("error opening {}", name);
@@ -331,6 +331,10 @@ impl Player {
         let mut refill_limit = arate * u32::from(dspec.channels);
         let underfill_limit = (arate * u32::from(dspec.channels) / 4).max(block_limit);
 
+        if start_time != NATimePoint::None {
+            let _ret = decoder.demuxer.seek(start_time);
+        }
+
         let mut eof = decoder.refill(&device);
         while !eof && device.size() < refill_limit {
             eof = decoder.refill(&device);
@@ -523,11 +527,29 @@ fn main() {
         return;
     }
 
-    for arg in args[1..].iter() {
-        player.play_file(arg, &cmd_receiver);
-        if player.ended {
-            break;
-        }
+    let mut aiter = args[1..].iter();
+    let mut start_time = NATimePoint::None;
+    while let Some(arg) = aiter.next() {
+        match arg.as_str() {
+            "-start" => {
+                if let Some(arg) = aiter.next() {
+                    if let Ok(val) = arg.parse() {
+                        start_time = val;
+                    } else {
+                        println!("invalid time");
+                    }
+                } else {
+                    println!("argument is required");
+                }
+            },
+            _ => {
+                player.play_file(arg, &cmd_receiver, start_time);
+                if player.ended {
+                    break;
+                }
+                start_time = NATimePoint::None;
+            },
+        };
     }
     cmd_state.restore();