I'm trying to load a video with ofVideoPlayer within an ofThread but it crashes when I try.
btw i'm not trying to make a threaded video player, I just want to load a video in a thread grab some frames from it and then process them.
This is my thread class
#pragma once
#include "ofThread.h"
#include "ofMain.h"
class ThreadedObject: public ofThread
{
public:
/// Create a ThreadedObject and initialize the member
/// variable in an initialization list.
ThreadedObject()
{
}
/// Start the thread.
void start()
{
// Mutex blocking is set to true by default
// It is rare that one would want to use startThread(false).
startThread();
}
/// Signal the thread to stop. After calling this method,
/// isThreadRunning() will return false and the while loop will stop
/// next time it has the chance to.
void stop()
{
stopThread();
}
void threadedFunction()
{
ofVideoPlayer vid;
vid.loadMovie("01.mov");
vid.play();
}
};
And this is how its being called:
#include "ofApp.h"
void ofApp::setup()
{
}
void ofApp::update()
{
}
void ofApp::draw()
{
ofBackground(ofColor::black);
ofSetColor(ofColor::white);
}
void ofApp::keyPressed(int key)
{
if (key == 'a')
{
threadedObject.start();
}
else if (key == 's')
{
threadedObject.stop();
}
}