ofxHapPlayer Problems

Hi!
I am experiencing weird problems using ofxHapPlayer
I have an array of several (5) positions video[i] of ofxHapPlayer. I load 5 clips using a for loop, set their loops to none, and I start playing the first one, watching when it ends. If it is ended, I start playing at the same time the secon dand third clips on the array. They never appear. Seems like the other animations are being updated too, but I can not understand why. All clips last the same. Here it is my code.

<a class="attachment" href="/uploads/default/7374/531b224cf086ba84.cpp">ofApp.cpp</a> (2.5 KB) 

Any clues?
Thanks!

is it possible that the other two files are playing in the background while the first one is visible?

i believe that you’ll want to wait until the first file is finished playing until you start the second and third.

if( !video[0].getIsMovieDone() ){

	video[0].update();

} else {

	if( !video[1].getIsPlaying() ){
	
		video[1].play();
		video[2].play();
	}
	
	video[1].update();
    video[2].update();
}
1 Like

did something similar. in addition to the above, I had memory/playback issues with a regular array of hap players:

   vector< ofxHapPlayer> players;

instead I used

vector<ofPtr<ofxHapPlayer>>	idlePlayer;   

		ofDirectory dir ("movies");
		dir.listDir();
		for (int i = 0; i < dir.size(); i++) {
			ofPtr<ofxHapPlayer> v (new ofxHapPlayer());
			v->loadMovie("movies/" + dir.getFile(i).getFileName());
			v->setLoopState(OF_LOOP_NONE);		
			while (!v->isLoaded()) {
				ofSleepMillis(10);
				ofLog() << "sleeping" << endl;
			}
			idlePlayer.push_back(v);
		}
		currentIdlePlaying = 0;
		idlePlayer[currentIdlePlaying]->play();

worked flawlessly.

In the update code I used the following:

			if (idlePlayer[currentIdlePlaying]->getCurrentFrame() >= idlePlayer[currentIdlePlaying]->getTotalNumFrames()-1){
				idlePlayer[currentIdlePlaying]->stop(); 
				currentIdlePlaying = ofRandom(idlePlayer.size());
				idlePlayer[currentIdlePlaying]->setFrame(0);
				idlePlayer[currentIdlePlaying]->play();
			}
	idlePlayer[currentIdlePlaying]->update();

and then in draw:

		idlePlayer[currentIdlePlaying]->draw(0,0);

Edit: also see this post, some codec issues with media encoder & hap alpha:
https://github.com/bangnoise/ofxHapPlayer/issues/4#issuecomment-72866376

2 Likes

Hi Mantissa!
Thanks a lor for the tip. It has more to do with Kj1 answer, but it helped regarding the play method. THanks a lot!
D!

Thanks Kj1!
I guess it was me who answered you in that github thread :wink:
It looks like the memory allocation works in a strange fashion when it come to arrays.
I am using also a vector of pointers to the objects. I resize that vector dinamically in order to make it work. I don’t know why it works badly if you don’t handle (update-draw cycle) with the whole vector.
It looks like you can not play only a portion of the videos in an array: you have to play them all at the same time to make them work.
If you want to play first one, then two, then four etc… you have to create arrays of pointers of that lengths each time.
I know it sounds weird, but I could not find another solution…