pub struct MediaPlayer { /* private fields */ }
Expand description
A LibVLC media player plays one media (usually in a custom drawable).
Implementations§
Source§impl MediaPlayer
impl MediaPlayer
Sourcepub fn new(instance: &Instance) -> Option<MediaPlayer>
pub fn new(instance: &Instance) -> Option<MediaPlayer>
Create an empty Media Player object
Examples found in repository?
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}
Sourcepub fn set_media(&self, md: &Media)
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?
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}
Sourcepub fn event_manager<'a>(&'a self) -> EventManager<'a>
pub fn event_manager<'a>(&'a self) -> EventManager<'a>
Get the Event Manager from which the media player send event.
Sourcepub fn is_playing(&self) -> bool
pub fn is_playing(&self) -> bool
is_playing
Sourcepub fn play(&self) -> Result<(), ()>
pub fn play(&self) -> Result<(), ()>
Play
Examples found in repository?
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}
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>>, )
Sourcepub fn set_nsobject(&self, drawable: *mut c_void)
pub fn set_nsobject(&self, drawable: *mut c_void)
Set the NSView handler where the media player should render its video output.
Sourcepub fn get_nsobject(&self) -> Option<*mut c_void>
pub fn get_nsobject(&self) -> Option<*mut c_void>
Get the NSView handler previously set with set_nsobject().
Sourcepub fn set_xwindow(&self, drawable: u32)
pub fn set_xwindow(&self, drawable: u32)
Set an X Window System drawable where the media player should render its video output.
Sourcepub fn get_xwindow(&self) -> Option<u32>
pub fn get_xwindow(&self) -> Option<u32>
Get the X Window System window identifier previously set with set_xwindow().
Sourcepub fn set_hwnd(&self, drawable: *mut c_void)
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.
Sourcepub fn get_hwnd(&self) -> Option<*mut c_void>
pub fn get_hwnd(&self) -> Option<*mut c_void>
Get the Windows API window handle (HWND) previously set with set_hwnd().
Sourcepub fn set_time(&self, time: i64)
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.
Sourcepub fn get_position(&self) -> Option<f32>
pub fn get_position(&self) -> Option<f32>
Get movie position as percentage between 0.0 and 1.0.
Sourcepub fn set_position(&self, pos: f32)
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.
Sourcepub fn set_chapter(&self, chapter: i32)
pub fn set_chapter(&self, chapter: i32)
Set movie chapter (if applicable).
Sourcepub fn get_chapter(&self) -> Option<i32>
pub fn get_chapter(&self) -> Option<i32>
Get movie chapter.
Sourcepub fn chapter_count(&self) -> Option<i32>
pub fn chapter_count(&self) -> Option<i32>
Get movie chapter count.
Sourcepub fn chapter_count_for_title(&self, title: i32) -> Option<i32>
pub fn chapter_count_for_title(&self, title: i32) -> Option<i32>
Get title chapter count.
Sourcepub fn title_count(&self) -> Option<i32>
pub fn title_count(&self) -> Option<i32>
Get movie title count.
Sourcepub fn previous_chapter(&self)
pub fn previous_chapter(&self)
Set previous chapter (if applicable)
Sourcepub fn next_chapter(&self)
pub fn next_chapter(&self)
Set next chapter (if applicable)
Sourcepub fn is_seekable(&self) -> bool
pub fn is_seekable(&self) -> bool
Is this media player seekable?
Sourcepub fn program_scrambled(&self) -> bool
pub fn program_scrambled(&self) -> bool
Check if the current program is scrambled.
Sourcepub fn next_frame(&self)
pub fn next_frame(&self)
Display the next frame (if supported)
Navigate through DVD Menu.
Sourcepub fn set_video_title_display(&self, position: Position, timeout: u32)
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.
Sourcepub fn raw(&self) -> *mut libvlc_media_player_t
pub fn raw(&self) -> *mut libvlc_media_player_t
Returns raw pointer