Autoplay behaviour of ofVideoPlayer

Hello,
how can i prevent ofVideoPlayer from auto playing a video clip?
is this the expected behaviour?
stopping or pausing after loading does not work. Is loading happening in a thread?
I am using osx 10.15.4 and oF 0.11.0.

void ofApp::setup(){
    _player.load("clip.mp4");
//    _player.setPaused(true);
//    _player.stop();
}

void ofApp::update(){
    _player.update();
}

void ofApp::draw(){
    _player.draw(0, 0);
}

Any pointers?

i am also having troubles setting the loop state. it seems that getLoopState always returns OF_LOOP_NORMAL.

void ofApp::keyPressed(int key){
    switch(key){
        case ' ': _player.play(); break;
        case 'l': {
            if(_player.getLoopState() == OF_LOOP_NORMAL){
                ofLogNotice() << "current loop state: normal";
                _player.setLoopState(OF_LOOP_NONE);
            }else{
                ofLogNotice() << "current loop state: none or palindrome";
                _player.setLoopState(OF_LOOP_NORMAL);
            }
            break;
        }
    }
}

Hey Thomas.

This is definitely a bug and probably left over from when the call was blocking with the QuickTime API.

All the AVFoundation video stuff is asynchronous and means that actions in setup() after the ofVideoPlayer::load() is called don’t always take effect as the video can take a second or two to actually be loaded ( in another thread ). I think there could be a bunch of improvement for video playback relating to this.

We’re tracking this for the next patch release, could you see if the fix described here works for you?

I am not sure about the looping issue.

I do see that at the end of ofVideoPlayer::load the loop state is set to OF_LOOP_NORMAL:

Looking at all the setLoop cools in ofAVFoundationPlayer and ofAVFoundationVideoPlayer it seems like they should be getting set.

I wonder though if you might have to wait for the video to start playing for the calls to work?

1 Like

thanks @theo , i will have a look.
i was expecting it not to start automatically by default. maybe that is just my preference.

looping issue:
it gets set. but getting the loop state always returns OF_LOOP_NORMAL.

HI Thomas,
I was wondering if you fixed this. I’m having the same, (or a similar) problem. I’m calling video.setLoopState (OF_LOOP_NONE). But it doesn’t seem to have any effect. I’m trying it in setup, and update, and after play etc. The video just keeps playing and playing.
If I replace OF_LOOP_NONE with OF_LOOP_PALINDROME it does indeed play palindrome. So I guess the code is correct.

1 Like

are you using macOs? ofAVFoundationPlayer?

HI dimitre,
I’m using MacOS. I dont I know if I am using ofAVFoundationPlayer. the only thing I’ve setup is ofVideoPlayer.

Is ofAVFoundationPlayer something that works under the hood, or is it something I can set?
thanks in advance.

hey Chris, sorry, i am not a big help here.
I was developing on osx, switched to windows at one point at the project, as I had to deploy to windows anyways. As far as I remember the loop bug did not appear on windows.

I was able to set the loop state, just could not get it via the getLoopState getter. So I kept track of the state in the class that used the video player.