Property id is an isize, not a usize, and can be absent if 0

This commit is contained in:
Emmanuel Gil Peyrot 2019-06-18 18:32:33 +02:00
parent 939541599f
commit c429d88d1b
2 changed files with 6 additions and 6 deletions

View File

@ -256,7 +256,7 @@ pub fn run_mpv_command(instance: &Mpv, command: &str, args: &[&str]) -> Result<(
} }
} }
pub fn observe_mpv_property(instance: &Mpv, id: &usize, property: &str) -> Result<(), Error> { pub fn observe_mpv_property(instance: &Mpv, id: &isize, property: &str) -> Result<(), Error> {
let ipc_string = format!( let ipc_string = format!(
"{{ \"command\": [\"observe_property\", {}, \"{}\"] }}\n", "{{ \"command\": [\"observe_property\", {}, \"{}\"] }}\n",
id, id,
@ -337,7 +337,7 @@ pub fn listen(instance: &mut Mpv) -> Result<Event, Error> {
} }
"property-change" => { "property-change" => {
let name: String; let name: String;
let id: usize; let id: isize;
let data: MpvDataType; let data: MpvDataType;
if let Value::String(ref n) = e["name"] { if let Value::String(ref n) = e["name"] {
@ -347,9 +347,9 @@ pub fn listen(instance: &mut Mpv) -> Result<Event, Error> {
} }
if let Value::Number(ref n) = e["id"] { if let Value::Number(ref n) = e["id"] {
id = n.as_u64().unwrap() as usize; id = n.as_i64().unwrap() as isize;
} else { } else {
return Err(Error(ErrorCode::JsonContainsUnexptectedType)); id = 0;
} }
match e["data"] { match e["data"] {

View File

@ -38,7 +38,7 @@ pub enum Event {
PlaybackRestart, PlaybackRestart,
PropertyChange { PropertyChange {
name: String, name: String,
id: usize, id: isize,
data: MpvDataType, data: MpvDataType,
}, },
ChapterChange, ChapterChange,
@ -389,7 +389,7 @@ impl Mpv {
run_mpv_command(self, "playlist-next", &[]) run_mpv_command(self, "playlist-next", &[])
} }
pub fn observe_property(&self, id: &usize, property: &str) -> Result<(), Error> { pub fn observe_property(&self, id: &isize, property: &str) -> Result<(), Error> {
observe_mpv_property(self, id, property) observe_mpv_property(self, id, property)
} }