Sharp Video Play

Making a minimal C# video player in the Linux ought to be easy. I mean, both platforms are mature and something so basic should not present a problem.

GStreamer C# bindings seemed as a perfect choice at first. All needed was to "make" it. Simple enough - just use autogen.sh followed by make and enjoy the fruits of your labor.

That was a plan until I started the dependency dance. First I had to make GtkSharp myself since my latest library versions were too low for GStreamer. Then I had to get GStreamer. Then I had to get GStreamer plugins. And then I gave up.

Between compiling, downloading, and resolving dependencies I have installed around 50 packages, manually compiled multiple libraries, and I was still on the "just one more" stage. Call me spoiled, but I find this unacceptable.

Fortunately Linux is full of choices and my next try was with the MPlayerControl. It too needed a few packets on the top of a clean Mint 17 installation but nowhere close to the dependency hell:

# sudo apt-get install mono-complete monodevelop mplayer git

After that I had to get the latest MPlayerControl source:

# git clone https://github.com/majorsilence/MPlayerControl MPlayerControl

And that was it. Shockingly, example within the source was working perfectly albeit it was not the smallest one they could make. I created my own sample form (with a reference to the LibMPlayerCommon) to play a single file as simply as possible:

using System;
using System.Collections.Generic;
using System.IO;
using System.Windows.Forms;
using LibMPlayerCommon;

namespace TestMedia {
public class MainForm : Form {
private MPlayer mPlayer;

public MainForm() {
this.WindowState = FormWindowState.Maximized;
this.mPlayer = new MPlayer(this.Handle.ToInt32(), MplayerBackends.GL2);

this.Load += delegate(object sender, EventArgs e) {
this.Text = this.fileQueue.Peek();
this.mPlayer.Play("~/somefilename.mp4");
};
this.mPlayer.VideoExited += delegate(object sender, MplayerEvent e) {
this.Close();
};
}
}
}

While GStreamer more complete solution by far, I found MPlayerControl infinitely easier to use and setup.

One thought to “Sharp Video Play”

Leave a Reply

Your email address will not be published. Required fields are marked *