fix examples and documentation
All checks were successful
Build and test / check (pull_request) Successful in 1m58s
Build and test / build (pull_request) Successful in 1m59s
Build and test / docs (pull_request) Successful in 2m44s
Build and test / test (pull_request) Successful in 3m19s
Build and test / build (push) Successful in 1m56s
Build and test / check (push) Successful in 1m50s
Build and test / docs (push) Successful in 2m45s
Build and test / test (push) Successful in 3m29s
All checks were successful
Build and test / check (pull_request) Successful in 1m58s
Build and test / build (pull_request) Successful in 1m59s
Build and test / docs (pull_request) Successful in 2m44s
Build and test / test (pull_request) Successful in 3m19s
Build and test / build (push) Successful in 1m56s
Build and test / check (push) Successful in 1m50s
Build and test / docs (push) Successful in 2m45s
Build and test / test (push) Successful in 3m29s
This commit was merged in pull request #3.
This commit is contained in:
@@ -1,15 +1,19 @@
|
||||
use mpvipc::{MpvError, Mpv, MpvExt};
|
||||
use mpvipc::{Mpv, MpvError, MpvExt};
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), MpvError> {
|
||||
env_logger::init();
|
||||
|
||||
let mpv = Mpv::connect("/tmp/mpv.sock").await?;
|
||||
|
||||
let meta = mpv.get_metadata().await?;
|
||||
println!("metadata: {:?}", meta);
|
||||
|
||||
let playlist = mpv.get_playlist().await?;
|
||||
println!("playlist: {:?}", playlist);
|
||||
|
||||
let playback_time: f64 = mpv.get_property("playback-time").await?;
|
||||
println!("playback-time: {}", playback_time);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
use mpvipc::{MpvError, Mpv, MpvExt};
|
||||
use futures::StreamExt;
|
||||
use mpvipc::{parse_event_property, Event, Mpv, MpvDataType, MpvError, MpvExt, Property};
|
||||
|
||||
fn seconds_to_hms(total: f64) -> String {
|
||||
let total = total as u64;
|
||||
@@ -14,55 +15,49 @@ async fn main() -> Result<(), MpvError> {
|
||||
env_logger::init();
|
||||
|
||||
let mpv = Mpv::connect("/tmp/mpv.sock").await?;
|
||||
let pause = false;
|
||||
let playback_time = std::f64::NAN;
|
||||
let duration = std::f64::NAN;
|
||||
|
||||
mpv.observe_property(1, "path").await?;
|
||||
mpv.observe_property(2, "pause").await?;
|
||||
mpv.observe_property(3, "playback-time").await?;
|
||||
mpv.observe_property(4, "duration").await?;
|
||||
mpv.observe_property(5, "metadata").await?;
|
||||
loop {
|
||||
// TODO:
|
||||
// let event = mpv.event_listen()?;
|
||||
// match event {
|
||||
// Event::PropertyChange { id: _, property } => match property {
|
||||
// Property::Path(Some(value)) => println!("\nPlaying: {}[K", value),
|
||||
// Property::Path(None) => (),
|
||||
// Property::Pause(value) => pause = value,
|
||||
// Property::PlaybackTime(Some(value)) => playback_time = value,
|
||||
// Property::PlaybackTime(None) => playback_time = std::f64::NAN,
|
||||
// Property::Duration(Some(value)) => duration = value,
|
||||
// Property::Duration(None) => duration = std::f64::NAN,
|
||||
// Property::Metadata(Some(value)) => {
|
||||
// println!("File tags:[K");
|
||||
// if let Some(MpvDataType::String(value)) = value.get("ARTIST") {
|
||||
// println!(" Artist: {}[K", value);
|
||||
// }
|
||||
// if let Some(MpvDataType::String(value)) = value.get("ALBUM") {
|
||||
// println!(" Album: {}[K", value);
|
||||
// }
|
||||
// if let Some(MpvDataType::String(value)) = value.get("TITLE") {
|
||||
// println!(" Title: {}[K", value);
|
||||
// }
|
||||
// if let Some(MpvDataType::String(value)) = value.get("TRACK") {
|
||||
// println!(" Track: {}[K", value);
|
||||
// }
|
||||
// }
|
||||
// Property::Metadata(None) => (),
|
||||
// Property::Unknown { name: _, data: _ } => (),
|
||||
// },
|
||||
// Event::Shutdown => return Ok(()),
|
||||
// Event::Unimplemented => panic!("Unimplemented event"),
|
||||
// _ => (),
|
||||
// }
|
||||
// print!(
|
||||
// "{}{} / {} ({:.0}%)[K\r",
|
||||
// if pause { "(Paused) " } else { "" },
|
||||
// seconds_to_hms(playback_time),
|
||||
// seconds_to_hms(duration),
|
||||
// 100. * playback_time / duration
|
||||
// );
|
||||
// io::stdout().flush().unwrap();
|
||||
|
||||
let mut events = mpv.get_event_stream().await;
|
||||
while let Some(Ok(event)) = events.next().await {
|
||||
match event {
|
||||
mpvipc::Event::PropertyChange { .. } => match parse_event_property(event)? {
|
||||
(1, Property::Path(Some(value))) => println!("\nPlaying: {}", value),
|
||||
(2, Property::Pause(value)) => {
|
||||
println!("Pause: {}", value);
|
||||
}
|
||||
(3, Property::PlaybackTime(Some(value))) => {
|
||||
println!("Playback time: {}", seconds_to_hms(value));
|
||||
}
|
||||
(4, Property::Duration(Some(value))) => {
|
||||
println!("Duration: {}", seconds_to_hms(value));
|
||||
}
|
||||
(5, Property::Metadata(Some(value))) => {
|
||||
println!("File tags:");
|
||||
if let Some(MpvDataType::String(value)) = value.get("ARTIST") {
|
||||
println!(" Artist: {}", value);
|
||||
}
|
||||
if let Some(MpvDataType::String(value)) = value.get("ALBUM") {
|
||||
println!(" Album: {}", value);
|
||||
}
|
||||
if let Some(MpvDataType::String(value)) = value.get("TITLE") {
|
||||
println!(" Title: {}", value);
|
||||
}
|
||||
if let Some(MpvDataType::String(value)) = value.get("TRACK") {
|
||||
println!(" Track: {}", value);
|
||||
}
|
||||
}
|
||||
_ => (),
|
||||
},
|
||||
Event::Shutdown => return Ok(()),
|
||||
Event::Unimplemented(_) => panic!("Unimplemented event"),
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user