2015-11-30 13:06:06 +00:00
|
|
|
// Copyright (c) 2015 T. Okubo
|
|
|
|
// This file is part of vlc-rs.
|
|
|
|
// Licensed under the MIT license, see the LICENSE file.
|
|
|
|
|
2018-02-27 13:52:21 +00:00
|
|
|
use sys;
|
2015-11-30 13:42:25 +00:00
|
|
|
use ::{Instance, Media, EventManager};
|
2015-11-30 13:06:06 +00:00
|
|
|
|
|
|
|
pub struct MediaList {
|
2018-06-03 06:37:41 +00:00
|
|
|
pub(crate) ptr: *mut sys::libvlc_media_list_t,
|
2015-11-30 13:06:06 +00:00
|
|
|
}
|
|
|
|
|
2015-11-30 13:42:25 +00:00
|
|
|
impl MediaList {
|
|
|
|
/// Create an empty media list.
|
|
|
|
pub fn new(instance: &Instance) -> Option<MediaList> {
|
|
|
|
unsafe{
|
2018-02-27 13:52:21 +00:00
|
|
|
let p = sys::libvlc_media_list_new(instance.ptr);
|
2015-11-30 13:42:25 +00:00
|
|
|
if p.is_null() { None }else{ Some(MediaList{ptr: p}) }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Associate media instance with this media list instance.
|
|
|
|
/// If another media instance was present it will be released. The libvlc_media_list_lock should NOT be held upon entering this function.
|
|
|
|
pub fn set_media(&self, md: &Media) {
|
2018-02-27 13:52:21 +00:00
|
|
|
unsafe{ sys::libvlc_media_list_set_media(self.ptr, md.ptr); }
|
2015-11-30 13:42:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Get media instance from this media list instance.
|
|
|
|
/// The MediaList::lock should NOT be held upon entering this function.
|
|
|
|
pub fn media(&self) -> Option<Media> {
|
|
|
|
unsafe{
|
2018-02-27 13:52:21 +00:00
|
|
|
let p = sys::libvlc_media_list_media(self.ptr);
|
2015-11-30 13:42:25 +00:00
|
|
|
if p.is_null() { None }else{ Some(Media{ptr: p}) }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Add media instance to media list.
|
|
|
|
/// The MediaList::lock should be held upon entering this function.
|
|
|
|
pub fn add_media(&self, md: &Media) -> Result<(), ()> {
|
|
|
|
unsafe{
|
2018-02-27 13:52:21 +00:00
|
|
|
if sys::libvlc_media_list_add_media(self.ptr, md.ptr) == 0 { Ok(()) }else{ Err(()) }
|
2015-11-30 13:42:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Insert media instance in media list on a position.
|
|
|
|
/// The MediaList::lock should be held upon entering this function.
|
|
|
|
pub fn insert_media(&self, md: &Media, pos: i32) -> Result<(), ()> {
|
|
|
|
unsafe{
|
2018-02-27 13:52:21 +00:00
|
|
|
if sys::libvlc_media_list_insert_media(self.ptr, md.ptr, pos) == 0 { Ok(()) }else{ Err(()) }
|
2015-11-30 13:42:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Remove media instance from media list on a position.
|
|
|
|
/// The MediaList::lock should be held upon entering this function.
|
|
|
|
pub fn remove_index(&self, pos: i32) -> Result<(), ()> {
|
|
|
|
unsafe{
|
2018-02-27 13:52:21 +00:00
|
|
|
if sys::libvlc_media_list_remove_index(self.ptr, pos) == 0 { Ok(()) }else{ Err(()) }
|
2015-11-30 13:42:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Get count on media list items.
|
|
|
|
/// The MediaList::lock should be held upon entering this function.
|
|
|
|
pub fn count(&self) -> i32 {
|
2018-02-27 13:52:21 +00:00
|
|
|
unsafe{ sys::libvlc_media_list_count(self.ptr) }
|
2015-11-30 13:42:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// List media instance in media list at a position.
|
|
|
|
/// The MediaList::lock should be held upon entering this function.
|
|
|
|
pub fn item_at_index(&self, pos: i32) -> Option<Media> {
|
|
|
|
unsafe{
|
2018-02-27 13:52:21 +00:00
|
|
|
let p = sys::libvlc_media_list_item_at_index(self.ptr, pos);
|
2015-11-30 13:42:25 +00:00
|
|
|
if p.is_null() { None }else{ Some(Media{ptr: p}) }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Find index position of List media instance in media list.
|
|
|
|
pub fn index_of_item(&self, md: &Media) -> Option<i32> {
|
|
|
|
unsafe{
|
2018-02-27 13:52:21 +00:00
|
|
|
let i = sys::libvlc_media_list_index_of_item(self.ptr, md.ptr);
|
2015-11-30 13:42:25 +00:00
|
|
|
if i == -1 { None }else{ Some(i) }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// This indicates if this media list is read-only from a user point of view.
|
|
|
|
pub fn is_readonly(&self) -> bool {
|
2018-02-27 13:52:21 +00:00
|
|
|
unsafe{ if sys::libvlc_media_list_is_readonly(self.ptr) == 0 { false }else{ true } }
|
2015-11-30 13:42:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Get lock on media list items
|
|
|
|
pub fn lock(&self) {
|
2018-02-27 13:52:21 +00:00
|
|
|
unsafe{ sys::libvlc_media_list_lock(self.ptr); }
|
2015-11-30 13:42:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Release lock on media list items
|
|
|
|
/// The libvlc_media_list_lock should be held upon entering this function.
|
|
|
|
pub fn unlock(&self) {
|
2018-02-27 13:52:21 +00:00
|
|
|
unsafe{ sys::libvlc_media_list_unlock(self.ptr); }
|
2015-11-30 13:42:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Get EventManager from this media list instance.
|
|
|
|
pub fn event_manager<'a>(&'a self) -> EventManager<'a> {
|
|
|
|
unsafe{
|
2018-02-27 13:52:21 +00:00
|
|
|
let p = sys::libvlc_media_list_event_manager(self.ptr);
|
2015-11-30 13:42:25 +00:00
|
|
|
assert!(!p.is_null());
|
|
|
|
EventManager{ptr: p, _phantomdata: ::std::marker::PhantomData}
|
|
|
|
}
|
|
|
|
}
|
2018-06-03 06:37:41 +00:00
|
|
|
|
|
|
|
/// Returns raw pointer
|
|
|
|
pub fn raw(&self) -> *mut sys::libvlc_media_list_t {
|
|
|
|
self.ptr
|
|
|
|
}
|
2015-11-30 13:42:25 +00:00
|
|
|
}
|
|
|
|
|
2015-11-30 13:06:06 +00:00
|
|
|
impl Drop for MediaList {
|
|
|
|
fn drop(&mut self) {
|
2018-02-27 13:52:21 +00:00
|
|
|
unsafe{ sys::libvlc_media_list_release(self.ptr) };
|
2015-11-30 13:06:06 +00:00
|
|
|
}
|
|
|
|
}
|