vlc/
media_library.rs

1// Copyright (c) 2015 T. Okubo
2// This file is part of vlc-rs.
3// Licensed under the MIT license, see the LICENSE file.
4
5use sys;
6use ::{Instance, MediaList};
7
8pub struct MediaLibrary {
9    pub(crate) ptr: *mut sys::libvlc_media_library_t,
10}
11
12impl MediaLibrary {
13    /// Create an new Media Library object.
14    pub fn new(instance: &Instance) -> Option<MediaLibrary> {
15        unsafe{
16            let p = sys::libvlc_media_library_new(instance.ptr);
17            if p.is_null() { None }else{ Some(MediaLibrary{ptr: p}) }
18        }
19    }
20
21    /// Load media library.
22    pub fn load(&self) -> Result<(), ()> {
23        unsafe{
24            if sys::libvlc_media_library_load(self.ptr) == 0 { Ok(()) }else{ Err(()) }
25        }
26    }
27
28    /// Get media library subitems.
29    pub fn media_list(&self) -> Option<MediaList> {
30        unsafe{
31            let p = sys::libvlc_media_library_media_list(self.ptr);
32            if p.is_null() { None }else{ Some(MediaList{ptr: p}) }
33        }
34    }
35
36    /// Returns raw pointer
37    pub fn raw(&self) -> *mut sys::libvlc_media_library_t {
38        self.ptr
39    }
40}
41
42impl Drop for MediaLibrary {
43    fn drop(&mut self) {
44        unsafe{ sys::libvlc_media_library_release(self.ptr) };
45    }
46}