vlc-rs/src/audio.rs

60 lines
1.7 KiB
Rust
Raw Normal View History

// Copyright (c) 2015 T. Okubo
// This file is part of vlc-rs.
// Licensed under the MIT license, see the LICENSE file.
2019-11-25 11:10:17 +00:00
use vlc_sys as sys;
2019-11-15 12:20:24 +00:00
use crate::MediaPlayer;
use crate::TrackDescription;
use crate::tools::from_cstr;
pub trait MediaPlayerAudioEx {
fn get_mute(&self) -> Option<bool>;
2019-11-15 12:20:53 +00:00
fn set_mute(&self, muted: bool);
fn get_volume(&self) -> i32;
fn set_volume(&self, volume: i32) -> Result<(), ()>;
2015-12-19 02:23:20 +00:00
fn get_audio_track_description(&self) -> Option<Vec<TrackDescription>>;
}
impl MediaPlayerAudioEx for MediaPlayer {
fn get_mute(&self) -> Option<bool> {
2018-02-27 13:52:21 +00:00
let r = unsafe{ sys::libvlc_audio_get_mute(self.ptr) };
if r == 0 {
Some(false)
}else if r == -1 {
None
}else{
Some(true)
}
}
fn set_mute(&self, status: bool) {
2018-02-27 13:52:21 +00:00
unsafe{ sys::libvlc_audio_set_mute(self.ptr, if status { 1 }else{ 0 }) };
}
fn get_volume(&self) -> i32 {
2018-02-27 13:52:21 +00:00
unsafe{ sys::libvlc_audio_get_volume(self.ptr) }
}
fn set_volume(&self, volume: i32) -> Result<(), ()> {
unsafe{
2018-02-27 13:52:21 +00:00
if sys::libvlc_audio_set_volume(self.ptr, volume) == 0 { Ok(()) }else{ Err(()) }
}
}
2015-12-19 02:23:20 +00:00
fn get_audio_track_description(&self) -> Option<Vec<TrackDescription>> {
unsafe{
2018-02-27 13:52:21 +00:00
let p0 = sys::libvlc_audio_get_track_description(self.ptr);
2015-12-19 02:23:20 +00:00
if p0.is_null() { return None; }
let mut td = Vec::new();
let mut p = p0;
while !(*p).p_next.is_null() {
td.push(TrackDescription{ id: (*p).i_id, name: from_cstr((*p).psz_name) });
p = (*p).p_next;
}
2018-02-27 13:52:21 +00:00
sys::libvlc_track_description_list_release(p0);
2015-12-19 02:23:20 +00:00
Some(td)
}
}
}