Openframeworks: ofVideoPlayer always starts playing, even when calling stop after loading.

Created on 17 Jan 2020  路  7Comments  路  Source: openframeworks/openFrameworks

calling stop right after loading the movie doesn't have any effect, same after loadAsync

#include "ofApp.h"
ofVideoPlayer mPlayer;

//--------------------------------------------------------------
void ofApp::dragEvent(ofDragInfo dragInfo){
    mPlayer.loadAsync( dragInfo.files[0] );
    mPlayer.stop(); // <-- this doesn't do anything
}

//--------------------------------------------------------------
void ofApp::setup(){

}

//--------------------------------------------------------------
void ofApp::update(){

    if( mPlayer.isLoaded() )
        mPlayer.update();
}

//--------------------------------------------------------------
void ofApp::draw(){



    if( mPlayer.isLoaded() ){
        mPlayer.draw(0,0);
    }
}

Most helpful comment

Definitely seems like a bug.
I think this is due to how macOS loads videos - the video isn't immediately available, so the commands might not be available. Will look into this for 0.11.1

Thanks!

All 7 comments

I've noticed ofVideoPlayer starts playing too, but when using Gstreamer it doesn't.

Definitely seems like a bug.
I think this is due to how macOS loads videos - the video isn't immediately available, so the commands might not be available. Will look into this for 0.11.1

Thanks!

Thanks, I did a bit of looking around and it seems that this line is triggering the play:
bPlaying = (rate != 0); in ofAVFoundationVideoPlayer.m

@Hperigo did you actually find a fix for this?

hi @fred-dev, not really =/

@Hperigo I think this might be a fix.

Let me know if it works for you.

Change these lines:
https://github.com/openframeworks/openFrameworks/blob/patch-release/libs/openFrameworks/video/ofAVFoundationVideoPlayer.m

to:

    // auto-play or play if started before beeing ready
    if(bAutoPlayOnLoad || bPlayStateBeforeLoad) {
        [self play];
    }else{
        [self pause];
    }

For me calling ofVideoPlayer::stop or not calling ofVideoPlayer::play after ofVideoPlayer::load now results in the movie stopped instead of being auto played.

ha - was trying to reproduce this but its already fixed.
closing! :)

Was this page helpful?
0 / 5 - 0 ratings