Struct MediaPlayer

Source
pub struct MediaPlayer { /* private fields */ }
Expand description

A LibVLC media player plays one media (usually in a custom drawable).

Implementations§

Source§

impl MediaPlayer

Source

pub fn new(instance: &Instance) -> Option<MediaPlayer>

Create an empty Media Player object

Examples found in repository?
examples/cli_player.rs (line 24)
11fn main() {
12    let args: Vec<String> = std::env::args().collect();
13
14    let path = match args.get(1) {
15        Some(s) => s,
16        None => {
17            println!("Usage: cli_audio_player path_to_a_media_file");
18            return;
19        }
20    };
21    let instance = Instance::new().unwrap();
22    
23    let md = Media::new_path(&instance, path).unwrap();    
24    let mdp = MediaPlayer::new(&instance).unwrap();
25    
26    let (tx, rx) = channel::<()>();
27    
28    let em = md.event_manager();
29    let _ = em.attach(EventType::MediaStateChanged, move |e, _| {
30        match e {
31            Event::MediaStateChanged(s) => {
32                println!("State : {:?}", s);
33                if s == State::Ended || s == State::Error {
34                    tx.send(()).unwrap();
35                }
36            },
37            _ => (),
38        }
39    });
40    
41    mdp.set_media(&md);
42    
43    // Start playing
44    mdp.play().unwrap();
45    
46    // Wait for end state
47    rx.recv().unwrap();    
48}
Source

pub fn set_media(&self, md: &Media)

Set the media that will be used by the media_player. If any, previous md will be released.

Examples found in repository?
examples/cli_player.rs (line 41)
11fn main() {
12    let args: Vec<String> = std::env::args().collect();
13
14    let path = match args.get(1) {
15        Some(s) => s,
16        None => {
17            println!("Usage: cli_audio_player path_to_a_media_file");
18            return;
19        }
20    };
21    let instance = Instance::new().unwrap();
22    
23    let md = Media::new_path(&instance, path).unwrap();    
24    let mdp = MediaPlayer::new(&instance).unwrap();
25    
26    let (tx, rx) = channel::<()>();
27    
28    let em = md.event_manager();
29    let _ = em.attach(EventType::MediaStateChanged, move |e, _| {
30        match e {
31            Event::MediaStateChanged(s) => {
32                println!("State : {:?}", s);
33                if s == State::Ended || s == State::Error {
34                    tx.send(()).unwrap();
35                }
36            },
37            _ => (),
38        }
39    });
40    
41    mdp.set_media(&md);
42    
43    // Start playing
44    mdp.play().unwrap();
45    
46    // Wait for end state
47    rx.recv().unwrap();    
48}
Source

pub fn get_media(&self) -> Option<Media>

Get the media used by the media_player.

Source

pub fn event_manager<'a>(&'a self) -> EventManager<'a>

Get the Event Manager from which the media player send event.

Source

pub fn is_playing(&self) -> bool

is_playing

Source

pub fn play(&self) -> Result<(), ()>

Play

Examples found in repository?
examples/cli_player.rs (line 44)
11fn main() {
12    let args: Vec<String> = std::env::args().collect();
13
14    let path = match args.get(1) {
15        Some(s) => s,
16        None => {
17            println!("Usage: cli_audio_player path_to_a_media_file");
18            return;
19        }
20    };
21    let instance = Instance::new().unwrap();
22    
23    let md = Media::new_path(&instance, path).unwrap();    
24    let mdp = MediaPlayer::new(&instance).unwrap();
25    
26    let (tx, rx) = channel::<()>();
27    
28    let em = md.event_manager();
29    let _ = em.attach(EventType::MediaStateChanged, move |e, _| {
30        match e {
31            Event::MediaStateChanged(s) => {
32                println!("State : {:?}", s);
33                if s == State::Ended || s == State::Error {
34                    tx.send(()).unwrap();
35                }
36            },
37            _ => (),
38        }
39    });
40    
41    mdp.set_media(&md);
42    
43    // Start playing
44    mdp.play().unwrap();
45    
46    // Wait for end state
47    rx.recv().unwrap();    
48}
Source

pub fn set_pause(&self, do_pause: bool)

Pause or resume (no effect if there is no media)

Source

pub fn pause(&self)

Toggle pause (no effect if there is no media)

Source

pub fn stop(&self)

Stop (no effect if there is no media)

Source

pub fn set_callbacks<F>( &self, play: F, pause: Option<Box<dyn Fn(i64) + Send + 'static>>, resume: Option<Box<dyn Fn(i64) + Send + 'static>>, flush: Option<Box<dyn Fn(i64) + Send + 'static>>, drain: Option<Box<dyn Fn() + Send + 'static>>, )
where F: Fn(*const c_void, u32, i64) + Send + 'static,

Source

pub fn set_nsobject(&self, drawable: *mut c_void)

Set the NSView handler where the media player should render its video output.

Source

pub fn get_nsobject(&self) -> Option<*mut c_void>

Get the NSView handler previously set with set_nsobject().

Source

pub fn set_xwindow(&self, drawable: u32)

Set an X Window System drawable where the media player should render its video output.

Source

pub fn get_xwindow(&self) -> Option<u32>

Get the X Window System window identifier previously set with set_xwindow().

Source

pub fn set_hwnd(&self, drawable: *mut c_void)

Set a Win32/Win64 API window handle (HWND) where the media player should render its video output. If LibVLC was built without Win32/Win64 API output support, then this has no effects.

Source

pub fn get_hwnd(&self) -> Option<*mut c_void>

Get the Windows API window handle (HWND) previously set with set_hwnd().

Source

pub fn get_time(&self) -> Option<i64>

Get the current movie time (in ms).

Source

pub fn set_time(&self, time: i64)

Set the movie time (in ms). This has no effect if no media is being played. Not all formats and protocols support this.

Source

pub fn get_position(&self) -> Option<f32>

Get movie position as percentage between 0.0 and 1.0.

Source

pub fn set_position(&self, pos: f32)

Set movie position as percentage between 0.0 and 1.0. This has no effect if playback is not enabled. This might not work depending on the underlying input format and protocol.

Source

pub fn set_chapter(&self, chapter: i32)

Set movie chapter (if applicable).

Source

pub fn get_chapter(&self) -> Option<i32>

Get movie chapter.

Source

pub fn chapter_count(&self) -> Option<i32>

Get movie chapter count.

Source

pub fn will_play(&self) -> bool

Is the player able to play.

Source

pub fn chapter_count_for_title(&self, title: i32) -> Option<i32>

Get title chapter count.

Source

pub fn set_title(&self, title: i32)

Set movie title.

Source

pub fn get_title(&self) -> Option<i32>

Get movie title.

Source

pub fn title_count(&self) -> Option<i32>

Get movie title count.

Source

pub fn previous_chapter(&self)

Set previous chapter (if applicable)

Source

pub fn next_chapter(&self)

Set next chapter (if applicable)

Source

pub fn get_rate(&self) -> f32

Get the requested movie play rate.

Source

pub fn set_rate(&self, rate: f32) -> Result<(), ()>

Set movie play rate.

Source

pub fn state(&self) -> State

Get current movie state.

Source

pub fn has_vout(&self) -> u32

How many video outputs does this media player have?

Source

pub fn is_seekable(&self) -> bool

Is this media player seekable?

Source

pub fn can_pause(&self) -> bool

Can this media player be paused?

Source

pub fn program_scrambled(&self) -> bool

Check if the current program is scrambled.

Source

pub fn next_frame(&self)

Display the next frame (if supported)

Source

pub fn navigate(&self, navigate: u32)

Navigate through DVD Menu.

Source

pub fn set_video_title_display(&self, position: Position, timeout: u32)

Set if, and how, the video title will be shown when media is played.

Source

pub fn raw(&self) -> *mut libvlc_media_player_t

Returns raw pointer

Trait Implementations§

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.