From: Kostya Shishkov Date: Mon, 4 Jan 2021 13:32:12 +0000 (+0100) Subject: sndplay: support -start option X-Git-Url: https://git.nihav.org/?a=commitdiff_plain;h=36ac48e5c692d34bce560528426634c0d75c5c8b;p=nihav-player.git sndplay: support -start option --- diff --git a/sndplay/src/main.rs b/sndplay/src/main.rs index 176a6d1..43f8fca 100644 --- a/sndplay/src/main.rs +++ b/sndplay/src/main.rs @@ -228,7 +228,7 @@ impl Player { buf: Vec::new(), } } - fn play_file(&mut self, name: &str, cmd_receiver: &mpsc::Receiver) { + fn play_file(&mut self, name: &str, cmd_receiver: &mpsc::Receiver, 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();