VLC and C# April 21, 2008
Posted by spunkyvt in Programming.Tags: C#, VLAN, VLANCONTROL, VLC
1 comment so far
I have found a cool way to embed media (dvd,mp3,mpeg,avi) into your apps.
You will need to use VLC The greatest players out there.
Also you will need to compile the library here
Build the library and add reference in your project
Place a picturebox or panel on the form and a button.
Add this code to form
VLanControl.VlcUserControl vlc = new VLanControl.VlcUserControl();
On the button click
vlc.Width = pictureBox1.Width;
vlc.Height = pictureBox1.Height;
vlc.Parent = pictureBox1;
vlc.CreateControl();
pictureBox1.Controls.Add(vlc);
vlc.AddAndPlay(@”C:\media”,”");
That is it!!!!
There are some options that you can set..but the act a little funny
Let’s say you wanted to add a marquee to the video.
Instead of using the vlc.AddAndPlay use this
vlc.ClearPlayList();
string[] opts = {“sub-filter=marq” };
vlc.AddToPlayList(@”C:\media”, “”, opts);
vlc.SetConfigVariable(“marq-position”, “0″);
vlc.SetConfigVariable(“marq-marquee”, “MY Marquee”);
vlc.SetConfigVariable(“volume”, “0″);
vlc.Play();
What is strange about this?? well if you use the SetConfigVariable to set the sub-filter=marq this will fail also if you put the setConfigVariable commands in the opts they will fail. This was the only way i could get the desired behavior.
Alright!!! What about skipping and moving and all that jazz.
OK!!! OK!! Hold on.
Put a timer and track bar on your form.
Put this in your button click also
while (vlc.IsPlaying == false)
{
Application.DoEvents();
}
trackBar1.Maximum = vlc.Length;
trackBar1.Minimum = 0;
timer1.Enabled = true;
timer1.Start();
You will need the while loop to make sure that the trackbar gets the right information from your vlc instance.
On the Tick event of the timer
try
{
if (vlc.IsPlaying)
trackBar1.Value = vlc.Time;
}
catch (Exception ex)
{
}
And in the TrackBar_Scroll Event
try
{
if (trackBar1.Value > vlc.Time)
{
vlc.Shuttle((trackBar1.Value – vlc.Time));
}
else
{
vlc.Shuttle(-(vlc.Time – trackBar1.Value));
}
}
catch
{
}
That is all I have for now. Enjoy!