mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer-rs.git
synced 2024-12-23 00:26:31 +00:00
Simplify player example a bit
This commit is contained in:
parent
d654252e65
commit
4276cb6228
1 changed files with 7 additions and 20 deletions
|
@ -4,12 +4,9 @@ extern crate gstreamer as gst;
|
|||
extern crate gstreamer_player as gst_player;
|
||||
|
||||
extern crate glib;
|
||||
|
||||
#[allow(unused_imports)]
|
||||
#[cfg(feature = "gst-player")]
|
||||
use glib::ObjectExt;
|
||||
|
||||
extern crate send_cell;
|
||||
|
||||
use std::env;
|
||||
|
||||
pub mod utils;
|
||||
|
@ -27,9 +24,7 @@ fn main_loop(uri: &str) -> Result<(), utils::ExampleError> {
|
|||
.set_property("uri", &glib::Value::from(uri))
|
||||
.expect("Can't set uri property");
|
||||
|
||||
let result = std::cell::RefCell::new(Some(Ok(())));
|
||||
let error = std::sync::Arc::new(std::sync::Mutex::new(send_cell::SendCell::new(result)));
|
||||
let error_clone = error.clone();
|
||||
let error = std::sync::Arc::new(std::sync::Mutex::new(Ok(())));
|
||||
|
||||
let player_clone = player.clone();
|
||||
let main_loop_clone = main_loop.clone();
|
||||
|
@ -42,19 +37,18 @@ fn main_loop(uri: &str) -> Result<(), utils::ExampleError> {
|
|||
|
||||
let player_clone = player.clone();
|
||||
let main_loop_clone = main_loop.clone();
|
||||
let error_clone = error.clone();
|
||||
player.connect_error(move |_, err| {
|
||||
let main_loop = &main_loop_clone;
|
||||
let player = &player_clone;
|
||||
|
||||
let error = std::sync::Arc::clone(&error_clone);
|
||||
let guard = error.lock().unwrap();
|
||||
let cell = &*guard;
|
||||
let refcell = cell.get();
|
||||
*refcell.borrow_mut() = Some(Err(utils::ExampleError::ElementError(
|
||||
let mut guard = error.lock().unwrap();
|
||||
*guard = Err(utils::ExampleError::ElementError(
|
||||
"player".to_owned(),
|
||||
err.clone(),
|
||||
"".to_owned(),
|
||||
)));
|
||||
));
|
||||
|
||||
player.stop();
|
||||
main_loop.quit();
|
||||
|
@ -64,15 +58,8 @@ fn main_loop(uri: &str) -> Result<(), utils::ExampleError> {
|
|||
main_loop.run();
|
||||
|
||||
let guard = error.as_ref().lock().unwrap();
|
||||
let cell = &*guard;
|
||||
let refcell = cell.get();
|
||||
let result = refcell.borrow();
|
||||
|
||||
if let Some(ref e) = *result {
|
||||
return e.clone();
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
guard.clone()
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "gst-player"))]
|
||||
|
|
Loading…
Reference in a new issue