Dynamic declarations / calls

Hi

I’m using multiple (30+) instances of ofVideoPlayer. I have a question whether it’s possible to declare / call them dynamically in a loop instead of doing it one by one?

Thanks for any advice

PM

Yes you can

in your header file declare the container ( vector) and the number of videos

  
  
int nVideos;  
vector< ofVideoPlayer > videos;  
  

then in your .cpp file setup the instances

  
  
void testApp::setup(){  
nVideos = 10;  
    for(int i =0; i < nVideos; i++){  
        ofVideoPlayer video;  
        video.loadMovie("movies/your_movie.mov");  
        videos.push_back(video);  
    }  
}  
  

You can then access them via

  
  
void testApp::update(){  
for(int i =0; i < nVideos; i++){  
        videos[i].update();  
    }  
}