Starting a movie with keyPress

#include “ofApp.h”

//--------------------------------------------------------------
void ofApp::setup() {
ofBackground(0);
myFlash.setup();
mySounds.setup();
video.loadMovie(“liveSet2small.mov”);
video.play();

movieStart = false;
}

//--------------------------------------------------------------
void ofApp::update() {
video.update();
mySounds.update();
myFlash.update();
}

//--------------------------------------------------------------
void ofApp::draw() {
video.draw(0, 0, ofGetWindowWidth(), ofGetWindowHeight());
myFlash.draw();
mySounds.draw();
}

//--------------------------------------------------------------
void ofApp::keyPressed(int key) {
myFlash._keyPressed(key);
mySounds.__keyPressed(key);

}

I’d like to start playing a movie with a keyPress by setting “movieStart” to true when I press ‘z’.

I wrote

If (key == ‘z’){
movieStart = true
}

in the keyPressed function and put the ofVideoPlayer functions in brackets so they would only be accessible if movieStart was set to true.

This is the first way I wrote it:

void ofApp::setup() {
ofBackground(0);
myFlash.setup();
mySounds.setup();
video.loadMovie(“liveSet2small.mov”);
video.play();

movieStart = false;
}

//--------------------------------------------------------------
void ofApp::update() {
video.update();
mySounds.update();
myFlash.update();
}

//--------------------------------------------------------------
void ofApp::draw() {
if (movieStart == true) {
video.draw(0, 0, ofGetWindowWidth(), ofGetWindowHeight());
}
myFlash.draw();
mySounds.draw();
}

//--------------------------------------------------------------
void ofApp::keyPressed(int key) {
myFlash._keyPressed(key);
mySounds.__keyPressed(key);
if (key == ‘z’) {
movieStart = true;
}
}

This made it so that the video wouldn’t start until I press ‘z’ but the audio plays anyways.

Here’s the script with a few more changes:

void ofApp::setup() {
ofBackground(0);
myFlash.setup();
mySounds.setup();
video.loadMovie(“liveSet2small.mov”);
if (movieStart == true) {
&ofVideoPlayer::play;
}

movieStart = false;
}

//--------------------------------------------------------------
void ofApp::update() {
if (movieStart == true) {
&ofVideoPlayer::update;
}
mySounds.update();
myFlash.update();
}

//--------------------------------------------------------------
void ofApp::draw() {
if (movieStart == true) {
video.draw(0, 0, ofGetWindowWidth(), ofGetWindowHeight());
}
myFlash.draw();
mySounds.draw();
}

//--------------------------------------------------------------
void ofApp::keyPressed(int key) {
myFlash._keyPressed(key);
mySounds.__keyPressed(key);
if (key == ‘z’) {
movieStart = true;
}
}

However, this stops the video from playing entirely, even after ‘z’ is pressed.

I’d like there to be no video or sound playing until I press ‘z’. How can I change this script to accomplish that?

Thanks!

maybe with video.setPaused()
Please look at the documentation
http://openframeworks.cc/documentation/video/ofVideoPlayer/#show_setPaused

When you the above in the setup(), you haven’t set movieStart yet – move that line above so that it’s

movieStart = false;
if (movieStart == true) {
video.play() //or just don’t put this anywhere in setup() and leave out the whole ‘if’ statement
}

So then in your key pressed function

if (key==‘z’) video.play();

that should get you playing the video with a keystoke

This worked. Thanks!