diff --git a/src/audio.rs b/src/audio.rs index 68e0e8a..39a2be4 100644 --- a/src/audio.rs +++ b/src/audio.rs @@ -45,6 +45,7 @@ impl MediaPlayerAudioEx for MediaPlayer { } } } + fn get_audio_track_description(&self) -> Option> { unsafe { let p0 = sys::libvlc_audio_get_track_description(self.ptr); diff --git a/src/core.rs b/src/core.rs index 93c8c9b..5bf6b56 100644 --- a/src/core.rs +++ b/src/core.rs @@ -53,7 +53,7 @@ impl Instance { /// Create and initialize a libvlc instance with specified args. /// Note: args.len() has to be less or equal to i32::MAX /// Note: libvlc discourages using arguments as these are not guaranteed to be stable between different versions of libvlc - pub fn with_args(args: Option>) -> Option { + pub fn with_args(args: Option>) -> Result { let args_c_ptr: Vec<*const c_char>; let args_c: Vec; if let Some(argv) = args { @@ -74,15 +74,15 @@ impl Instance { }; if p.is_null() { - return None; + Err(InternalError) + } else { + Ok(Instance { ptr: p }) } - - Some(Instance { ptr: p }) } } /// Create and initialize a libvlc instance. - pub fn new() -> Option { + pub fn new() -> Result { Instance::with_args(None) } @@ -125,25 +125,25 @@ impl Instance { } /// Returns a list of audio filters that are available. - pub fn audio_filter_list_get(&self) -> Option { + pub fn audio_filter_list_get(&self) -> Result { unsafe { let p = sys::libvlc_audio_filter_list_get(self.ptr); if p.is_null() { - None + Err(InternalError) } else { - Some(ModuleDescriptionList { ptr: p }) + Ok(ModuleDescriptionList { ptr: p }) } } } /// Returns a list of video filters that are available. - pub fn video_filter_list_get(&self) -> Option { + pub fn video_filter_list_get(&self) -> Result { unsafe { let p = sys::libvlc_video_filter_list_get(self.ptr); if p.is_null() { - None + Err(InternalError) } else { - Some(ModuleDescriptionList { ptr: p }) + Ok(ModuleDescriptionList { ptr: p }) } } } diff --git a/src/media_library.rs b/src/media_library.rs index 8e66de8..3a6b236 100644 --- a/src/media_library.rs +++ b/src/media_library.rs @@ -3,6 +3,7 @@ // Licensed under the MIT license, see the LICENSE file. use crate::{Instance, InternalError, MediaList}; +use std::fmt; use vlc_sys as sys; pub struct MediaLibrary { @@ -11,13 +12,13 @@ pub struct MediaLibrary { impl MediaLibrary { /// Create an new Media Library object. - pub fn new(instance: &Instance) -> Option { + pub fn new(instance: &Instance) -> Result { unsafe { let p = sys::libvlc_media_library_new(instance.ptr); if p.is_null() { - None + Err(InternalError) } else { - Some(MediaLibrary { ptr: p }) + Ok(MediaLibrary { ptr: p }) } } } diff --git a/src/media_list.rs b/src/media_list.rs index 7eb99b1..b48022d 100644 --- a/src/media_list.rs +++ b/src/media_list.rs @@ -11,13 +11,13 @@ pub struct MediaList { impl MediaList { /// Create an empty media list. - pub fn new(instance: &Instance) -> Option { + pub fn new(instance: &Instance) -> Result { unsafe { let p = sys::libvlc_media_list_new(instance.ptr); if p.is_null() { - None + Err(InternalError) } else { - Some(MediaList { ptr: p }) + Ok(MediaList { ptr: p }) } } } @@ -45,6 +45,7 @@ impl MediaList { /// Add media instance to media list. /// The MediaList::lock should be held upon entering this function. + // TODO: use specific error type since documentation says "-1 if the media list is read-only" pub fn add_media(&self, md: &Media) -> Result<(), InternalError> { unsafe { if sys::libvlc_media_list_add_media(self.ptr, md.ptr) == 0 {