It is made with reason to make using mplayer slave mode from Vala much easier, and it contains just 4 methods:
public static void mplayer_start_playback_audio (string fifo, string name, string output);
used to play audio file
public static void mplayer_start_playback_video (string video, string subtitle_color, double subtitle_scale, string fifo, X.Window xwindow_id, string name, string output);
used to play video files and embed mplayer window to specified xid
public static void mplayer_send_command (string fifo, string command);
send command to mplayer to control: subtitles, aspect ratio, volume, brightness, ...
public static void mplayer_stop_playback (string fifo, string output);
stop mplayer playback and remove fifo and output files
To see how is to use this, here is example:
Code: Select all
// valac test.vala --pkg gtk+-3.0 --pkg libmp-control --target-glib=2.38
using Gtk;
using MPlayerControl;
class program : Gtk.Window
{
const string FIFO = "/tmp/fifo";
const string OUTPUT = "/tmp/output";
string file = "/root/test.mp3";
public program()
{
var button_play = new Gtk.Button.from_icon_name("media-playback-start-symbolic", Gtk.IconSize.LARGE_TOOLBAR);
var button_pause = new Gtk.Button.from_icon_name("media-playback-pause-symbolic", Gtk.IconSize.LARGE_TOOLBAR);
var button_rewind = new Gtk.Button.from_icon_name("media-skip-backward-symbolic", Gtk.IconSize.LARGE_TOOLBAR);
var button_forward = new Gtk.Button.from_icon_name("media-skip-forward-symbolic", Gtk.IconSize.LARGE_TOOLBAR);
var button_stop = new Gtk.Button.from_icon_name("media-playback-stop-symbolic", Gtk.IconSize.LARGE_TOOLBAR);
button_play.clicked.connect(() => { mplayer_stop_playback(FIFO, OUTPUT); mplayer_start_playback_audio(FIFO, file, OUTPUT); });
button_pause.clicked.connect(() => { mplayer_send_command(FIFO, "pause"); });
button_rewind.clicked.connect(() => { mplayer_send_command(FIFO, "seek -15"); });
button_forward.clicked.connect(() => { mplayer_send_command(FIFO, "seek +15"); });
button_stop.clicked.connect(() => { mplayer_stop_playback(FIFO, OUTPUT); });
var grid = new Gtk.Grid();
grid.attach(button_play, 0, 0, 1, 1);
grid.attach(button_pause, 1, 0, 1, 1);
grid.attach(button_rewind, 2, 0, 1, 1);
grid.attach(button_forward, 3, 0, 1, 1);
grid.attach(button_stop, 4, 0, 1, 1);
grid.set_row_homogeneous(true);
grid.set_column_homogeneous(true);
var window = new Gtk.Window();
window.window_position = WindowPosition.CENTER;
window.add(grid);
window.set_default_size(250, 50);
window.show_all();
window.destroy.connect(() => { mplayer_stop_playback(FIFO, OUTPUT); Gtk.main_quit(); });
}
public static int main (string[] args)
{
Gtk.init(ref args);
new program();
Gtk.main();
return 0;
}
}
(first you need to install this library with: packer -S libmp-control) then you would change string file = "/root/test.mp3"; to some audio file in your system