| 1 | // compile with: valac --pkg gtk+-2.0 slider-mplayer.vala -o slider-mplayer
|
|---|
| 2 | using Gtk;
|
|---|
| 3 |
|
|---|
| 4 | public class SliderMplayer : Window {
|
|---|
| 5 |
|
|---|
| 6 | private Label l1;
|
|---|
| 7 | private Label l2;
|
|---|
| 8 | private HScale slider;
|
|---|
| 9 | private HScale slider2;
|
|---|
| 10 | private IOChannel chan;
|
|---|
| 11 | private size_t bw;
|
|---|
| 12 |
|
|---|
| 13 | public SliderMplayer (string[] args ) {
|
|---|
| 14 | Intl.setlocale(LocaleCategory.ALL,"C");
|
|---|
| 15 | var filename=args[1];
|
|---|
| 16 | if((filename=="") || (filename==null)) {
|
|---|
| 17 | var file_chooser = new FileChooserDialog ("Open File", null,
|
|---|
| 18 | FileChooserAction.OPEN,
|
|---|
| 19 | STOCK_CANCEL, ResponseType.CANCEL,
|
|---|
| 20 | STOCK_OPEN, ResponseType.ACCEPT);
|
|---|
| 21 | if (file_chooser.run () == ResponseType.ACCEPT) {
|
|---|
| 22 | filename=file_chooser.get_filename ();
|
|---|
| 23 | }
|
|---|
| 24 | file_chooser.destroy ();
|
|---|
| 25 | }
|
|---|
| 26 | try {
|
|---|
| 27 | Process.spawn_command_line_async("rm -f /tmp/mplayer_fifo");
|
|---|
| 28 | Process.spawn_command_line_async("mkfifo /tmp/mplayer_fifo");
|
|---|
| 29 | Process.spawn_command_line_async("mplayer -slave -quiet -input file=/tmp/mplayer_fifo %s ".printf(filename));
|
|---|
| 30 | } catch (SpawnError e) {
|
|---|
| 31 | stderr.printf ("%s\n", e.message);
|
|---|
| 32 | }
|
|---|
| 33 | try {
|
|---|
| 34 | chan= new IOChannel.file("/tmp/mplayer_fifo", "r+");
|
|---|
| 35 | } catch (FileError e) {
|
|---|
| 36 | stderr.printf ("%s\n", e.message);
|
|---|
| 37 | }
|
|---|
| 38 | this.title = "SliderMPlayer";
|
|---|
| 39 | this.position = WindowPosition.CENTER;
|
|---|
| 40 | set_default_size (300, 20);
|
|---|
| 41 | this.destroy.connect(Gtk.main_quit);
|
|---|
| 42 |
|
|---|
| 43 | l1= new Label.with_mnemonic("Position");
|
|---|
| 44 | l2= new Label.with_mnemonic("Scale");
|
|---|
| 45 | slider = new HScale.with_range (0, 100, 1);
|
|---|
| 46 | slider2 = new HScale.with_range (1, 10, 0.1);
|
|---|
| 47 | slider.adjustment.value=100;
|
|---|
| 48 |
|
|---|
| 49 | slider.adjustment.value_changed.connect (() => {
|
|---|
| 50 | chan.write_chars("sub_pos %d 1\n".printf((int)slider.adjustment.value).to_utf8(), out bw);
|
|---|
| 51 | chan.flush();
|
|---|
| 52 | });
|
|---|
| 53 |
|
|---|
| 54 | slider2.adjustment.value_changed.connect (() => {
|
|---|
| 55 | chan.write_chars("sub_scale %0.2f 1\n".printf(slider2.adjustment.value).to_utf8(), out bw);
|
|---|
| 56 | chan.flush();
|
|---|
| 57 | });
|
|---|
| 58 |
|
|---|
| 59 | var hbox = new HBox (true, 5);
|
|---|
| 60 | var hbox2 = new HBox (true, 5);
|
|---|
| 61 | var vbox = new VBox (true, 5);
|
|---|
| 62 | hbox.add (l1);
|
|---|
| 63 | hbox.add (slider);
|
|---|
| 64 | hbox2.add (l2);
|
|---|
| 65 | hbox2.add (slider2);
|
|---|
| 66 | vbox.add(hbox);
|
|---|
| 67 | vbox.add(hbox2);
|
|---|
| 68 | add (vbox);
|
|---|
| 69 | }
|
|---|
| 70 |
|
|---|
| 71 | public static int main (string[] args) {
|
|---|
| 72 | Gtk.init (ref args);
|
|---|
| 73 | var window = new SliderMplayer (args);
|
|---|
| 74 | window.show_all ();
|
|---|
| 75 | Gtk.main ();
|
|---|
| 76 | return 0;
|
|---|
| 77 | }
|
|---|
| 78 | }
|
|---|