weird problem not being able to play video :S

Hi all, I have a very weird problem I can’t figure out.

I have a TextureManager class, which is a wrapper for a texture. The Texture can come from an ofImage, ofVideoPlayer, ofVideoGrabber and anything else. So it has a ofBaseHasTexture *tex;

In my app (which is fullscreen), when I press ‘o’ I bring up an openDialog panel, and you can select an image or video, and it gets loaded, later I can use it’s texture without caring about it’s source. My problem is, if I select a video, it doesn’t play the video at all, it plays the audio for a few seconds, and then stops.

My loadTexture works fine, if I manually call loadTexture(<url_to_movie>) from testApp::setup(), it loads and plays the movie fine. If I select the same movie via the openDialog, it loads the movie fine and displays the first frame, plays the first few seconds of the audio, and then stops! No more video, no more audio. I’m going crazy trying to figure it out. If I call vid->play() in the update, THEN it does work. What is going on?

Code is below, (you will noticed some really ghetto counter stuff going on because when the app is fullscreen the openDialog doesn’t open, switching fullscreen off doesn’t take place immediately but takes place 2 frames later).

  
  
  
  
void TextureManager::loadTexture(string n) {  
    name = n;  
      
    if(tex) {  
        delete tex;  
        tex = NULL;  
    }  
      
    if(numFiles == 0) {  
        tex = NULL;  
        return;  
    }  
      
    bool bSuccess;  
    if(name.find(".mov") != string::npos) { // if it's a movie  
        ofLog(OF_LOG_VERBOSE, "TextureManager::loadTexture " + name + " is movie");  
        ofVideoPlayer *vid = new ofVideoPlayer;  
        bSuccess = vid->loadMovie(name);  
        vid->setLoopState(OF_LOOP_NORMAL);  
        vid->play();  
        tex = vid;  
        bIsVideo = true;  
    } else {  
        ofLog(OF_LOG_VERBOSE, "TextureManager::loadTexture " + name + " is image");  
        ofImage *img = new ofImage();  
        bSuccess = img->loadImage(name);  
        tex = img;  
        bIsVideo = false;  
    }  
      
    if(bSuccess == false) {  
        ofLog(OF_LOG_ERROR, "Error loading texture");  
    } else {  
        ofLog(OF_LOG_VERBOSE, "Loading texture success");  
    }  
}  
  
// this gets called when user presses 'o'  
void TextureManager::openDialog() {  
    ofSetFullscreen(false);  
    openDialogCounter = 1;  
}  
  
// protected method:  
void TextureManager::_openDialog() {  
    openDialogCounter = 0;  
    int result = [oPanel runModal];  
      
    if(result == NSFileHandlingPanelOKButton) {  
        NSArray *urls = [oPanel filenames];  
        loadTexture([[urls objectAtIndex:0] UTF8String]);  
    }  
      
    ofSetFullscreen(true);  
}  
  
// called from testApp::update()  
void TextureManager::update() {  
    if(openDialogCounter) {  
        openDialogCounter++;  
        if(openDialogCounter == 4) _openDialog();  
    }  
      
    if(tex && bIsVideo) {  
        ofVideoPlayer *vid = (ofVideoPlayer*)tex;  
//      vid->play();        // I have to uncomment this for it to work!  
        vid->update();  
    }  
}