-
Notifications
You must be signed in to change notification settings - Fork 17
Play a video using Winform Control
Peter Gill edited this page Aug 15, 2020
·
5 revisions
Add a reference to LibMPlayerCommon, LibImages, and LibMPlayerWinform.
Create a new file and class called test2 and paste in this code. You now have a working video/audio player.
using System;
using System.Windows.Forms;
using LibMPlayerCommon;
namespace Test
{
static class Test2
{
[STAThread]
static void Main()
{
System.Windows.Forms.Form frm = new System.Windows.Forms.Form();
frm.Height = 600;
frm.Width = 800;
LibMPlayerWinform.WinFormMPlayerControl playerControl = new LibMPlayerWinform.WinFormMPlayerControl();
var player = LibMPlayerCommon.PlayerFactory.Get(playerControl.Handle, @"C:\Users\Peter\Desktop\mplayer.exe");
playerControl.SetPlayer(player);
playerControl.Dock = DockStyle.Fill;
playerControl.MPlayerPath = @"C:\Users\Peter\Desktop\mplayer.exe";
playerControl.VideoPath = @"C:\Users\Peter\Downloads\sintel_trailer-720p.mp4";
frm.Controls.Add(playerControl);
Application.Run(frm);
}
}
}
Imports System.Windows.Forms
Imports LibMPlayerCommon
Namespace Test
NotInheritable Class Test2
Private Sub New()
End Sub
<STAThread> _
Private Shared Sub Main()
Dim frm As New System.Windows.Forms.Form()
frm.Height = 600
frm.Width = 800
Dim playerControl As New LibMPlayerWinform.WinFormMPlayerControl()
var player = LibMPlayerCommon.PlayerFactory.Get(playerControl.Handle, "C:\Users\Peter\Desktop\mplayer.exe")
playerControl.SetPlayer(player)
playerControl.Dock = DockStyle.Fill
playerControl.MPlayerPath = "C:\Users\Peter\Desktop\mplayer.exe"
playerControl.VideoPath = "C:\Users\Peter\Downloads\sintel_trailer-720p.mp4"
frm.Controls.Add(playerControl)
Application.Run(frm)
End Sub
End Class
End Namespace
As we can see in the example above the most simple way to add video is to create an instance of the LibMPlayerWinform.WinFormMPlayerControl user control and add it to a form. Then set the path to mplayer.exe and your video and you are good to go.