Click here to Skip to main content
15,886,769 members
Please Sign up or sign in to vote.
4.56/5 (2 votes)
See more:
Hi everyone,

I am new to this forum and am a beginner programmer.

I wish to develop a motion detector program in Visual Basic.NET. I've tried the windows API for connecting the webcam to my project.
While surfing the net I came across to this forum and found a project which uses AForge.net. I downloaded and installed the framework and tried a certain project, to learn what is what.
I decided to rewrite the code myself, but encountered an error in the line
VB
If VideoSourcePlayer1.Isrunning = True Then

It says that VideoSourcePlayer1 is not declared. It may be inaccessible due to its protection level.

Here is the code that I am trying to rewrite. The VideoSourcePlayer1 doesn't have an error.
I'm merely rewriting the code, so why am I encountering an error when it seems to work fine on the other project?

Kindly help me.

Thanks in advance.

VB
Imports AForge.Video
Imports AForge.Video.DirectShow

Public Class MainWindow
    Dim VideoCaptureSource As VideoCaptureDevice
    Dim WCdevices As New FilterInfoCollection(FilterCategory.VideoInputDevice)


    Private Sub MainWindow_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        Dim MyWebcam As FilterInfo

        If WCdevices.Count = 0 Then
            lstWCdevices.Items.Add("No Webcam Device Detected")
        Else
            For Each MyWebcam In WCdevices
                lstWCdevices.Items.Add(MyWebcam.Name)
            Next
        End If
        lstWCdevices.SelectedIndex = 0
    End Sub



    Private Sub btnStart_Click(sender As Object, e As EventArgs) Handles btnStart.Click
        If lstWCdevices.SelectedItem <> "No Video Devices" Then


            If VideoSourcePlayer1.IsRunning = True Then
                VideoSourcePlayer1.SignalToStop()
                VideoSourcePlayer1.WaitForStop()
            End If

            VideoCaptureSource = New VideoCaptureDevice(VideoDevices(cboVideoSource.SelectedIndex).MonikerString)
            VideoSourcePlayer1.VideoSource = VideoCaptureSource
            VideoSourcePlayer1.Start()
        End If
    End Sub
End Class
Posted
Updated 5-Feb-17 7:30am
v3

Hello,

The error your describing - protection level errors are about scope. That object: VideoSourcePlayer1 is inaccessible from the class you are trying to call it from. In the code pieces you provided, I don't see it declared anywhere either.

I would look for it's declaration, and make sure it is being declared in such a way that it's available to the class you are calling it from - or pass it to the class you need to call it from.

Hope this helps...

- Pete
 
Share this answer
 
v2
Comments
Member 9626615 27-Jan-13 11:19am    
Hi Pete, the code posted above isn't mine and a while ago i saw from the project's designer, in the InitializeComponent(), that VideoSourcePlayer1 is there and realized that it's an object. sorry, i forgot to mention that in the project that i downloaded, i can't see any design or object in the form. i tried to imitate the lines

'
'VideoSourcePlayer1
'
Me.VideoSourcePlayer1.Location = New System.Drawing.Point(15, 59)
Me.VideoSourcePlayer1.Name = "VideoSourcePlayer1"
Me.VideoSourcePlayer1.Size = New System.Drawing.Size(320, 240)
Me.VideoSourcePlayer1.TabIndex = 2
Me.VideoSourcePlayer1.Text = "VideoSourcePlayer1"
Me.VideoSourcePlayer1.VideoSource = Nothing

and

Friend WithEvents VideoSourcePlayer1 As AForge.Controls.VideoSourcePlayer

below. the error vanished, my webcam is now opening but can't see any output. So what do I have to do to get this object: VideoSourcePlayer1, do I have to import anything or what? thanks :)
This is the key line here, I think:

VB
Friend WithEvents VideoSourcePlayer1 As AForge.Controls.VideoSourcePlayer


It's not just an object, it's a 3rd party control - and it's found in the AForge class. It has Events - and I think you probably aren't handling them. I think you need to dig through the example project and find where the events are being handled, and replicate that in your own project. When you do that I think you will get video.

I think your almost there... And yes - just judging for what you just posted, I'm not surprised that you don't see anything in the designer. See this:

VB
Me.videoSourcePlayer1.Location =...


They're positioning the control manually. There probably isn't anything in the designer you'll see.

- Pete
 
Share this answer
 
v2
Comments
Member 9626615 27-Jan-13 12:14pm    
thanks Pete but i guess i'll have to look for another reference though i find it hard to find project that uses aforge in vb.net.
I searched the project thoroughly like you told me but i can't see any event or declaration regarding VideoSourcePlayer1 aside from the codes I've posted above. I appreciate your effort helping me with this problem. Thank you.
pdoxtader 27-Jan-13 13:30pm    
Have you had a look at AForge's website yet? I only had a quick look, but from what I saw there is a wealth of documentation and example projects for most (if not all) of the functionality the library offers. I think you will find what you need there.

http://www.aforgenet.com/aforge/framework/
pdoxtader 27-Jan-13 13:33pm    
For example, on this page you will find 6 sample projects you can download.

http://www.aforgenet.com/framework/samples/image_processing.html
Member 9626615 27-Jan-13 22:30pm    
good day pdoxtader, thanks for the advice i realized that aforgenet.com is working perfectly fine, i was trying to open that site yesterday and no matter how i try it won't open that's why i find it hard to get references, ill fix this problem in connecting to the site first. I'll get back here once i start doing my project again. Thank you.
Guys, i finally found this VideoSourcePlayer1. So this is an object that you have to add first in the toolbox. what i did is, right click the toolbox > Choose Items > Browse and add the aforge.controls.dll, then components including VideoSourcePlayer appeared and that's it :) thank you for helping.
 
Share this answer
 
If you are using NuGet to load AForge, note that the AForge.Controls package must be separately loaded. THEN create a new tab in Toolbox, call it AForge, right-click in the empty tab and select Choose Items, then Browse to your solution folder, then down to packages, then into AForge.Controls.2.2.5, into lib, then select Aforge.Controls.dll.

Now you should be able to drag/drop a Video Source Player from the Toolbox onto your form in design mode.
 
Share this answer
 
you need to add aforge.net references to your project. then you go to the toolbox and add the videosource component. its important to make sure that you paste the aforge dll files into your project files and reference them from there: chizz is there for you all the time
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900