5
public class BeatBox.StreamPlayer : GLib.Object {
12
public signal void end_of_stream(Song s);
13
public signal void current_position_update(int64 position);
15
public StreamPlayer(string[] args) {
17
play = ElementFactory.make ("playbin", "play");
19
bus.add_watch(bus_callback);
21
loop = new MainLoop();
22
var time = new TimeoutSource(500);
24
time.set_callback(() => {
26
Gst.Format fmt = Gst.Format.TIME;
27
play.query_position(ref fmt, out position);
28
current_position_update(position);
32
time.attach(loop.get_context());
35
private bool bus_callback (Gst.Bus bus, Gst.Message message) {
36
switch (message.type) {
37
case Gst.MessageType.ERROR:
40
message.parse_error (out err, out debug);
41
stdout.printf ("Error: %s\n", err.message);
43
case Gst.MessageType.EOS:
44
end_of_stream(current);
53
public void play_song (Song s) {
54
if(s.file.length > 2) {// play a new file
56
play.uri = "file://" + s.file;
57
play.set_state(State.READY);
61
play.set_state(State.PLAYING);
64
public void play_stream() {
65
play.set_state(State.PLAYING);
68
public void pause_stream() {
69
play.set_state(State.PAUSED);
72
public void seek_position(int64 position) {
73
if(play.current_state != State.PLAYING)
74
play.seek_simple(Gst.Format.TIME, Gst.SeekFlags.FLUSH, position);
76
play.seek_simple(Gst.Format.TIME, Gst.SeekFlags.FLUSH, position);