Commit b7f06569 authored by Felix Häcker's avatar Felix Häcker

wip: move audioplayer to gradio crate

parent 521e33cd
......@@ -415,6 +415,7 @@ dependencies = [
"gdk-pixbuf 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"gio 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"glib 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
"gstreamer 0.11.1 (registry+https://github.com/rust-lang/crates.io-index)",
"gtk 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
"pretty_env_logger 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
......@@ -1031,7 +1032,7 @@ name = "rustio"
version = "0.1.0"
dependencies = [
"failure 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"gstreamer 0.11.1 (registry+https://github.com/rust-lang/crates.io-index)",
"glib 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
"gtk 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
"reqwest 0.8.5 (registry+https://github.com/rust-lang/crates.io-index)",
......
......@@ -13,6 +13,7 @@ gdk = "0.8.0"
reqwest = "0.8.5"
gdk-pixbuf = "0.4.0"
url = "1.7.0"
gstreamer = "0.11.1"
[dependencies.gtk]
version = "0.4.0"
......
......@@ -4,13 +4,13 @@ version = "0.1.0"
authors = ["Felix Häcker <haecker.felix1207@gmail.com>"]
[dependencies]
gstreamer = "0.11.1"
reqwest = "0.8.5"
serde = "1.0.43"
serde_json = "1.0"
serde_derive = "1.0.43"
log = "0.4"
failure = "0.1.1"
glib = "0.5.0"
[dependencies.gtk]
version = "0.4.0"
......
......@@ -4,12 +4,11 @@
extern crate serde;
extern crate serde_json;
extern crate reqwest;
extern crate gstreamer;
extern crate gtk; // TODO: Don't require gtk
extern crate glib;
pub mod error;
pub mod client;
pub mod audioplayer;
pub mod station;
pub mod country;
pub mod state;
......
......@@ -8,10 +8,11 @@ use gtk::prelude::*;
use std::cell::RefCell;
use std::rc::Rc;
use rustio::{audioplayer::AudioPlayer, client::Client};
use rustio::{client::Client};
use favicon_downloader::FaviconDownloader;
use library::Library;
use audioplayer::AudioPlayer;
use page::library_page::LibraryPage;
use page::search_page::SearchPage;
......@@ -38,6 +39,7 @@ pub struct AppUI {
pub struct GradioApp {
gtk_app: gtk::Application,
app_state: Rc<RefCell<AppState>>,
app_ui: Rc<RefCell<AppUI>>,
}
......@@ -96,6 +98,8 @@ impl GradioApp {
self.app_ui.borrow().library_page.update_stations(&self.app_state.borrow().library.stations);
let app_state = self.app_state.clone();
self.connect_signals();
self.gtk_app.run(&[]);
}
......
extern crate gstreamer;
extern crate gtk;
use gstreamer::{Element, ElementFactory, ElementExt, Bus, Message, Continue, MessageView, State};
use gstreamer::prelude::*;
use station::Station;
use rustio::station::Station;
use std::rc::Rc;
use client::Client;
use std::sync::mpsc::{channel, Sender, Receiver};
use rustio::client::Client;
pub struct AudioPlayer{
playbin: Element,
......@@ -14,16 +16,24 @@ pub struct AudioPlayer{
station_changed_cb: Vec<Box<Fn(&AudioPlayer)>>,
}
enum BusNotification{
Playback(bool)
}
impl AudioPlayer{
pub fn new() -> AudioPlayer{
gstreamer::init();
let playbin = ElementFactory::make("playbin", "playbin").unwrap();
let bus = playbin.get_bus().expect("Unable to get playbin bus");
let client = Client::new();
let station = None;
let (bus_sender, bus_receiver) = channel();
bus.add_watch(move|bus, message|{
Self::bus_callback(&bus, &message, bus_sender.clone())
});
let ap = AudioPlayer{
playbin,
client,
......@@ -33,27 +43,35 @@ impl AudioPlayer{
station_changed_cb: Vec::new(),
};
bus.add_watch(|bus, message|{
Self::bus_callback(&bus, &message)
});
//ap.notification_loop(bus_receiver);
ap
}
fn bus_callback(bus: &Bus, message: &Message) -> Continue {
fn bus_callback(bus: &Bus, message: &Message, bus_sender: Sender<BusNotification>) -> Continue {
match message.view(){
MessageView::Tag(tag) => info!("tag"),
MessageView::StateChanged(sc) => {
match sc.get_current(){
State::Playing => info!("is playing"),
_ => info!("is notplaying"),
}
State::Playing => bus_sender.send(BusNotification::Playback(true)),
_ => bus_sender.send(BusNotification::Playback(false)),
};
}
_ => (),
}
Continue(true)
}
fn notification_loop(&self, bus_receiver: Receiver<BusNotification>){
gtk::timeout_add(100, move||{
match bus_receiver.try_recv().unwrap(){
BusNotification::Playback(playback) => {
//Self::emit_cb(&self.playback_changed_cb);
},
};
Continue(true)
});
}
pub fn playback(&self) -> bool{
if self.playbin.get_state(gstreamer::ClockTime::from_seconds(10)).1 == gstreamer::State::Playing{
return true;
......@@ -107,9 +125,9 @@ impl AudioPlayer{
}
}
fn emit_cb(vec: Vec<Box<Fn()>>){
fn emit_cb(vec: &Vec<Box<Fn(&AudioPlayer)>>){
for x in 0..vec.len(){
(*&vec[x])();
//(*&vec[x])();
}
}
}
\ No newline at end of file
......@@ -8,11 +8,13 @@ extern crate gio;
extern crate glib;
extern crate gtk;
extern crate reqwest;
extern crate gstreamer;
extern crate rusqlite;
extern crate rustio;
extern crate url;
mod app;
mod audioplayer;
mod favicon_downloader;
mod library;
mod page;
......
......@@ -7,8 +7,7 @@ use rustio::client::ClientUpdate;
use std::cell::RefCell;
use std::collections::HashMap;
use std::rc::Rc;
use std::sync::mpsc::channel;
use std::sync::mpsc::Sender;
use std::sync::mpsc::{channel, Sender};
use widgets::station_listbox::StationListBox;
pub struct SearchPage {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment