Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET
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
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.
 
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 27-Jan-13 3:20am
Edited 27-Jan-13 3:26am
v3
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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
  Permalink  
v2
Comments
Member 9626615 at 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 :)
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

This is the key line here, I think:
 
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:
 
Me.videoSourcePlayer1.Location =...

 
They're positioning the control manually. There probably isn't anything in the designer you'll see.
 
- Pete
  Permalink  
v2
Comments
Member 9626615 at 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 at 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 at 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 at 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.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

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 Smile | :) thank you for helping.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

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.
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 375
1 Sergey Alexandrovich Kryukov 195
2 Prakriti Goyal 177
3 jlopez788 134
4 Kruti Joshi 117
0 OriginalGriff 6,742
1 Sergey Alexandrovich Kryukov 5,479
2 Maciej Los 3,474
3 Peter Leow 3,313
4 DamithSL 2,505


Advertise | Privacy | Mobile
Web04 | 2.8.140721.1 | Last Updated 10 Mar 2014
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100