Click here to Skip to main content
15,886,830 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a problem when i try connect two IP camera (dlink-930l) using array. i use AForge library. all of video only shows in one picturebox alternately. what should i do to connect each camera in different picturebox. can i create array eventframehandler ?

C#
using AForge.Video;
public MJPEGStream[] VideoStream = new MJPEGStream[2];        
private string[] MetaUrl = {"http://192.168.0.3/video.cgi?","http://192.168.0.2/video.cgi?"};
private void Form1_Load(object sender, EventArgs e)
        {
            for (int i = 0; i < VideoStream.Length; i++)
            {
                VideoStream[i] = new MJPEGStream();
                VideoStream[i].Source = MetaUrl[i];
                VideoStream[i].Login = "admin";
                VideoStream[i].Password = "";
            }
        }
 private void button1_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < VideoStream.Length; i++)
            {
                VideoStream[i].Start();
                VideoStream[i].NewFrame += new NewFrameEventHandler(VideoStream_NewFrame1);
                k = i;
            }
        }
  public int k=0;
  private void VideoStream_NewFrame1(object sender, NewFrameEventArgs eventArgs)
        {            
            Bitmap FrameData = new Bitmap(eventArgs.Frame);
            PictureBox[] box = new PictureBox[2];
            box[0] = pictureBox1;
            box[1] = pictureBox2;
            box[k].Image = FrameData;            
        }


thank you master....
Posted

Not sure this will solve your problem, but when you create the event handler for the NewFrame event
C#
VideoStream[i].NewFrame += new NewFrameEventHandler(VideoStream_NewFrame1);

you will end up using the same method for both cameras.
This means that you need to make use of the sender parameter to figure out which camera is calling the method.
C#
[Updated]
using AForge.Video;
public MJPEGStream[] VideoStream = new MJPEGStream[2];        
private string[] MetaUrl = {"http://192.168.0.3/video.cgi?","http://192.168.0.2/video.cgi?"};
private PictureBox[] boxes;
private void Form1_Load(object sender, EventArgs e)
{
    boxes = new PictureBox[VideoStream.Length];
    for (int i = 0; i < VideoStream.Length; i++)
    {
        VideoStream[i] = new MJPEGStream();
        VideoStream[i].Source = MetaUrl[i];
        VideoStream[i].Login = "admin";
        VideoStream[i].Password = "";
        boxes[i].Tag = VideoStream[i];
    }
}

[Updated]
private void button1_Click(object sender, EventArgs e)
{
    for (int i = 0; i < VideoStream.Length; i++)
    {
        VideoStream[i].Start();
        VideoStream[i].NewFrame += new NewFrameEventHandler(VideoStream_NewFrame1);
    }
}

private void VideoStream_NewFrame1(object sender, NewFrameEventArgs eventArgs)
{
    [Updated]
    MJPEGStream vs = (sender as MJPEGStream); // I think MJPEGStream will be the type
    if (vs != null)
    {
        Bitmap FrameData = new Bitmap(eventArgs.Frame);
        foreach (PictureBox box in boxes)
        {
            if ((MJPEGStream)box.Tag == vs) // You might have to modify this comparison.
            {
                box.Image = FrameData;
                break;
            }
        }
    }     
}


If the class MJPEGStream contains a Tag property, it would be easier to use that.
 
Share this answer
 
v3
Comments
adjo-inggit 17-Sep-14 0:36am    
it doesn't work, it said VideoStream like a "field". i use "k" to get looping like "i". yeah, it always be set for last value of "i". but thanks before master.. is it possible to create array method ?
George Jonsson 17-Sep-14 0:52am    
I have corrected the code.
adjo-inggit 17-Sep-14 2:49am    
thank for your helping.. but i don't know how to get the index from vs, i'm newbie about c# programming... thank you for your kindness
George Jonsson 17-Sep-14 3:35am    
See my updated answer.
adjo-inggit 17-Sep-14 4:34am    
Thank you... master.... it works with a little edit....
i try edit your solution, and it's work !!!!!!!!!!!!!!!!!!!!!!!!!.. thank you master George Jonsson, here the code i have edited from your code...

C#
..
..
// private PictureBox[] boxes;
public PictureBox[] boxes = new PictureBox[2];
private void Form1_Load(object sender, EventArgs e)
     {
          //  boxes = new PictureBox[VideoStream.Length]; //it's make boxes is always null 
          boxes[0] = pictureBox1;
          boxes[1] = pictureBox2; 
          ...
          ...
     }

private void VideoStream_NewFrame1(object sender, NewFrameEventArgs eventArgs)
        {
          ...
          ...
         //breaks; it makes only one ip camera is viewed...   
        }
 
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