2006-05-19 19:24:35 +00:00
|
|
|
using System;
|
|
|
|
using GLib;
|
|
|
|
using Gst;
|
2009-05-06 12:09:23 +00:00
|
|
|
using Gst.BasePlugins;
|
2006-05-19 19:24:35 +00:00
|
|
|
|
|
|
|
public class PlayBinPlayer
|
|
|
|
{
|
|
|
|
private static MainLoop loop;
|
|
|
|
private static string[] songs;
|
|
|
|
private static int song_idx = 0;
|
|
|
|
private static PlayBin play;
|
|
|
|
|
|
|
|
public static void Main (string[] args)
|
|
|
|
{
|
|
|
|
if (args.Length < 1) {
|
|
|
|
Console.WriteLine ("usage: mono playbin-player.exe audio_file_uri");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
songs = args;
|
|
|
|
|
|
|
|
Gst.Application.Init ();
|
|
|
|
loop = new MainLoop ();
|
|
|
|
|
2009-05-21 19:47:17 +00:00
|
|
|
play = ElementFactory.Make ("playbin", "play") as PlayBin;
|
2006-05-19 19:24:35 +00:00
|
|
|
|
|
|
|
if (play == null) {
|
|
|
|
Console.WriteLine ("error creating a playbin gstreamer object");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
play.Uri = songs[song_idx++];
|
|
|
|
play.Bus.AddWatch (new BusFunc (BusCb));
|
|
|
|
play.SetState (State.Playing);
|
|
|
|
|
|
|
|
loop.Run ();
|
|
|
|
}
|
|
|
|
|
|
|
|
private static bool BusCb (Bus bus, Message message)
|
|
|
|
{
|
|
|
|
switch (message.Type) {
|
|
|
|
case MessageType.Error:
|
2009-05-01 13:28:34 +00:00
|
|
|
Enum err;
|
|
|
|
string msg;
|
|
|
|
message.ParseError (out err, out msg);
|
|
|
|
Console.WriteLine ("Gstreamer error: {0}", msg);
|
2006-05-19 19:24:35 +00:00
|
|
|
loop.Quit ();
|
|
|
|
break;
|
|
|
|
case MessageType.Eos:
|
|
|
|
if (song_idx >= songs.Length) {
|
|
|
|
Console.WriteLine ("Thank you, come again");
|
|
|
|
loop.Quit ();
|
|
|
|
} else {
|
|
|
|
play.SetState (State.Null);
|
|
|
|
play.Uri = songs[song_idx++];
|
|
|
|
play.SetState (State.Playing);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|