Quantcast
Channel: beginners - openFrameworks
Viewing all articles
Browse latest Browse all 4929

Starting a movie with keyPress

$
0
0

@ManuLeng wrote:

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!

Posts: 4

Participants: 3

Read full topic


Viewing all articles
Browse latest Browse all 4929

Trending Articles