[Gambas-user] MediaPlayer

Benoît Minisini g4mba5 at gmail.com
Sun Nov 15 18:01:49 CET 2020


Le 15/11/2020 à 09:06, Mike Crean via User a écrit :
> Hi all, I know I am probably missing a simple fix for my problem.
> 
> I have a picture box on a form and I wish to display a webcam in it.
> 
> When I try with the following code the web cam image floods the entire form
> 
> can anyone point me in the write direction so it is contained in the 
> picture box please.
> 
> 
> Best regards
> 
> Mike
> 
> 
> Private mp As New MediaPlayer
> 
> 
> Public Sub Form_Open()
> 
> Form.Load
> 
> Form.Show
> 
> PictureBox1.SetFocus()
> 
> mp.URL = "v4l2:///dev/video0"
> 
> mp.SetWindow(PictureBox1)
> 
> mp.Play()
> 
> End
> 
> 
> Public Sub Form_Close()
> 
> EndIt()
> 
> End
> 
> 
> Public Sub EndIt()
> 
> Try Quit
> 
> End
> 
> 
> Public Sub Button2_Click()
> 
> Dim theImage As Image = mp.Video.Image
> 
> theImage.Save(Application.Path &/ Format(Now, "ddmmyyyy_hhnnss") & ".jpg")
> 
> PictureBox1.Image = theImage
> 
> End
> 

The SetWindow() method needs a control that had a real X11 (or wayland) 
window, otherwise if will use the first parent control having a real 
window, which is usually the toplevel one.

Hopefully, there is a trick, used in the 'gb.form.media' component (that 
you can use as an example): using a DrawingArea with its Cached property 
set to TRUE. This is the only way to have a control having its own 
window whatever the GUI component in use.

Maybe I should made a dedicated control for that, so that the trick 
becomes explicit?

Regards,

-- 
Benoît Minisini


More information about the User mailing list