i need write some OSD information on my video i use libvlcsharp and videoview for play my videos. i saw when i play video, i can't access videos bitmap to draw some graphics on it this is my code and result thank for your help :)
public partial class Form1 : Form
{
private LibVLC libVLC;
private MediaPlayer mediaPlayer;
public Form1()
{
InitializeComponent();
libVLC = new LibVLC();
mediaPlayer = new MediaPlayer(libVLC);
var myMedia = new Media(libVLC, new Uri(@"C:\ffmpeg\Sample.mp4"));
mediaPlayer.Media = myMedia;
videoView1.MediaPlayer = mediaPlayer;
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void cmdPlay_Click(object sender, EventArgs e)
{
if (videoView1.MediaPlayer.IsPlaying)
{
cmdPlay.Text = "Play";
videoView1.MediaPlayer.Pause();
}
else
{
cmdPlay.Text = "Pause";
videoView1.MediaPlayer.Play();
}
}
private void videoView1_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
g.DrawString("Hello", new Font("Arial", 9, FontStyle.Bold), Brushes.White, new Point(10, 10));
}
private void cmdDrawOSD_Click(object sender, EventArgs e)
{
Graphics g = Graphics.FromHwnd(videoView1.Handle);
g.DrawString("Hello", new Font("Arial", 9, FontStyle.Bold), Brushes.White, new Point(20, 20));
}
private void cmdRewind_Click(object sender, EventArgs e)
{
videoView1.MediaPlayer.Stop();
}
}
videoview paint event is working before play any video, if you play any video, this code not draw anythings on screen
private void videoView1_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
g.DrawString("Hello", new Font("Arial", 9, FontStyle.Bold), Brushes.White, new Point(10, 10));
}
i try to access videoview graphics by this code
Graphics g = Graphics.FromHwnd(videoView1.Handle);
g.DrawString("Hello", new Font("Arial", 9, FontStyle.Bold), Brushes.White, new Point(20, 20));
and it's work if you don't play video, when you play a video ,this code don't work and you can't see anythings happend on videoview object.
Result without play video Result when play video
thanks for your attention
I try to access graphics handle but not successfuly yet when video play all drawing disappear
You can try drawing another window (frameless topmost window) on top of the first one and sync the move/resizes event on top of it.
This is what is done in LibVLCSharp.WPF, but for WPF