pub fn new() -> (Self, glib::Receiver<BackendMessage>) {
        gst::init().expect("Unable to initialize GStreamer");
        let playbin = gst::ElementFactory::make("playbin", None)
            .expect("Unable to create the `playbin` element");
        playbin.disable_video().ok(); // .ok() to ignore any errors

        // Asynchronous channel to communicate with main() with
        let (main_tx, main_rx) = MainContext::channel(Priority::default());
        // Handle messages from GSTreamer bus
        playbin
            .bus()
            .expect("Failed to get GStreamer message bus")
            .add_watch(glib::clone!(@strong main_tx => move |_bus, msg| {
                match msg.view() {
                    gst::MessageView::Eos(_) =>
                        main_tx.send(BackendMessage::ReachedEndOfPlaylist)
                        .expect("Unable to send message to main()"),
                    gst::MessageView::Error(e) =>
                        glib::g_debug!("song", "{}", e.error()),
                        _ => (),
                }
                glib::Continue(true)
            }))
            .expect("Failed to connect to GStreamer message bus");

        let this = Self {
            playbin,
            next_uri: Arc::new(Mutex::new(None)),
            main_tx,
        };

        // Switch to next song when reaching end of current track
        this.playbin
            .connect(
                "about-to-finish",
                false,
                glib::clone!(@strong this => move |_args| {
                   this.dequeue();
                   None
                }),
            )
            .expect("Failed to connect playbin's `about-to-finish` signal");

        // Update main() with backend state every 100ms
        glib::source::timeout_add(
            Duration::from_millis(100),
            glib::clone!(@strong this => move || {
               this.main_tx.send(BackendMessage::State(this.state()))
                   .expect("Unable to send message to main()");
            glib::Continue(true)
            }),
        );

        (this, main_rx)
    }
/// Initializes the GStreamer backend and sets up signal
/// handling. Returns a tupe with the new Backend object and
/// a Receiver for communication during playback.
Initializes the GStreamer backend and sets up signal
handling. Returns a tupe with the new Backend object and
a Receiver for communication during playback.
Initializes the GStreamer backend and sets up signal handling . Returns a tupe with the new Backend object and a Receiver for communication during playback .
pub fn new() -> (Self, glib::Receiver<BackendMessage>) {
        gst::init().expect("Unable to initialize GStreamer");
        let playbin = gst::ElementFactory::make("playbin", None)
            .expect("Unable to create the `playbin` element");
        playbin.disable_video().ok(); // .ok() to ignore any errors
        // Asynchronous channel to communicate with main() with
        let (main_tx, main_rx) = MainContext::channel(Priority::default());
        // Handle messages from GSTreamer bus
        playbin
            .bus()
            .expect("Failed to get GStreamer message bus")
            .add_watch(glib::clone!(@strong main_tx => move |_bus, msg| {
                match msg.view() {
                    gst::MessageView::Eos(_) =>
                        main_tx.send(BackendMessage::ReachedEndOfPlaylist)
                        .expect("Unable to send message to main()"),
                    gst::MessageView::Error(e) =>
                        glib::g_debug!("song", "{}", e.error()),
                        _ => (),
                }
                glib::Continue(true)
            }))
            .expect("Failed to connect to GStreamer message bus");
        let this = Self {
            playbin,
            next_uri: Arc::new(Mutex::new(None)),
            main_tx,
        };
        // Switch to next song when reaching end of current track
        this.playbin
            .connect(
                "about-to-finish",
                false,
                glib::clone!(@strong this => move |_args| {
                   this.dequeue();
                   None
                }),
            )
            .expect("Failed to connect playbin's `about-to-finish` signal");
        // Update main() with backend state every 100ms
        glib::source::timeout_add(
            Duration::from_millis(100),
            glib::clone!(@strong this => move || {
               this.main_tx.send(BackendMessage::State(this.state()))
                   .expect("Unable to send message to main()");
            glib::Continue(true)
            }),
        );
        (this, main_rx)
    }
pub fn new ( ) -> ( Self , glib :: Receiver < BackendMessage > ) { gst :: init ( ) . expect ( " " ) ; let playbin = gst :: ElementFactory :: make ( " " , None ) . expect ( " " ) ; playbin . disable_video ( ) . ok ( ) ; // .ok() to ignore any errors // Asynchronous channel to communicate with main() with let ( main_tx , main_rx ) = MainContext :: channel ( Priority :: default ( ) ) ; // Handle messages from GSTreamer bus playbin . bus ( ) . expect ( " " ) . add_watch ( glib :: clone ! ( strong main_tx move bus msg { match msg view ( ) { gst MessageView Eos ( ) main_tx send ( BackendMessage ReachedEndOfPlaylist ) expect ( " " ) gst MessageView Error ( e ) glib g_debug ( " " " " e error ( ) ) ( ) } glib Continue ( true ) } ) ) . expect ( " " ) ; let this = Self { playbin , next_uri : Arc :: new ( Mutex :: new ( None ) ) , main_tx , } ; // Switch to next song when reaching end of current track this . playbin . connect ( " " , false , glib :: clone ! ( strong this move args { this dequeue ( ) None } ) , ) . expect ( " " ) ; // Update main() with backend state every 100ms glib :: source :: timeout_add ( Duration :: from_millis ( 100 ) , glib :: clone ! ( strong this move { this main_tx send ( BackendMessage State ( this state ( ) ) ) expect ( " " ) glib Continue ( true ) } ) , ) ; ( this , main_rx ) }
Initializes the GStreamer backend and sets up signal
handling.
Initializes the GStreamer backend and sets up signal handling .