[Gambas-user] MediaPlayer

Charlie Ogier charlie at cogier.com
Sun Nov 15 16:37:17 CET 2020


Hi Mike,

Your program worked fine for me. Maybe the problem is how you set up 
your Form. I have rewritten the code to create the necessary component 
on the form. Try this code in a new 'graphical application'.

Charlie

*************************************
''Needs gb.media (and a webcam!)

MP As New MediaPlayer
PictureBox1 As PictureBox
HBox1 As HBox
Button2 As Button

Public Sub Form_Open()

   With Me
     .Height = 400
     .Width = 700
     .Padding = 5
     .Arrangement = Arrange.Vertical
   End With

   With PictureBox1 = New PictureBox(Me) As "PictureBox1"
     .Expand = True
   End With

   With HBox1 = New HBox(Me)
     .Height = 28
     .Invert = True
   End With

   With Button2 = New Button(HBox1) As "Button2"
     .Width = 120
     .Text = "&Take photo"
     .Picture = Picture["icon:/22/camera"]
   End With

   MP.URL = "v4l2:///dev/video0"
   MP.SetWindow(PictureBox1)
   MP.Play()

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
*************************************

On 15/11/2020 08:06, Mike Crean via User wrote:
>
> 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
>
>
>
>
>
>
> ----[ http://gambaswiki.org/wiki/doc/netiquette ]----

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20201115/d6cd1496/attachment.htm>


More information about the User mailing list