Skip to content

Instantly share code, notes, and snippets.

@lab101
Created August 24, 2017 13:04
Show Gist options
  • Save lab101/d5c900c86989d3a65d30f684509fbbd6 to your computer and use it in GitHub Desktop.
Save lab101/d5c900c86989d3a65d30f684509fbbd6 to your computer and use it in GitHub Desktop.
#include "cinder/app/App.h"
#include "cinder/app/RendererGl.h"
#include "cinder/gl/gl.h"
#include "cinder/Surface.h"
#include "cinder/gl/Texture.h"
#include "cinder/Utilities.h"
#include "cinder/qtime/QuickTimeGl.h"
using namespace ci;
using namespace ci::app;
using namespace std;
class QuickTimeSampleApp : public App {
public:
static void prepareSettings( Settings *settings ) { settings->setMultiTouchEnabled( false ); }
void setup() override;
void keyDown( KeyEvent event ) override;
void update() override;
void draw() override;
std::vector<std::string> files;
std::vector<qtime::MovieGlRef> movies;
int fileIndex =0;
int movieIndex =0;
float changeTime=0;
};
void QuickTimeSampleApp::setup()
{
files.push_back("big_buck_bunny_720p_stereo.ogg");
files.push_back("LFE-SBR.mp4");
files.push_back("sintel_trailer-1080p.ogv");
setWindowSize(1000,1000);
}
void QuickTimeSampleApp::keyDown( KeyEvent event )
{
if (event.getChar() == 'f'){
setFullScreen(!isFullScreen());
}else if(event.getChar() == ' '){
fs::path moviePath = getAssetPath( files[fileIndex] );
if(++fileIndex >= files.size()) fileIndex= 0;
qtime::MovieGlRef mMovie = qtime::MovieGl::create( moviePath );
movies.push_back(mMovie);
//mMovie->setLoop();
mMovie->play();
}else if(event.getChar() == 's'){
if(++movieIndex >= movies.size()) movieIndex= 0;
fs::path moviePath = getAssetPath( files[fileIndex] );
movies[movieIndex]->stop();
movies[movieIndex] = qtime::MovieGl::create( moviePath );
if(++fileIndex >= files.size()) fileIndex= 0;
}else if(event.getChar() == 'x'){
for(auto& m : movies){
m->stop();
}
movies.clear();
}
}
void QuickTimeSampleApp::update()
{
//if(ci::app::getElapsedSeconds() - changeTime > 6){
// changeTime = ci::app::getElapsedSeconds();
//}
for( auto& m : movies){
if(!m->isPlaying() && m->isPlayable())
{
m->play();
}
}
}
void QuickTimeSampleApp::draw()
{
gl::clear( Color( 0, 0, 0 ) );
int i =0;
int y=20;
int x=0;
for( auto& m : movies){
gl::draw( m->getTexture(), Rectf(x,y,x+320,y+240) );
ci::gl::drawString(ci::toString(i+1) + ": size:" + ci::toString(m->getWidth()) + "x" + ci::toString(m->getHeight()), vec2(x, y+242));
i++;
x+= 320;
if(x > ci::app::getWindowWidth()-250) {
x=0;
y+=250;
}
}
ci::gl::drawString("time: " + ci::toString(ci::app::getElapsedSeconds()), vec2(20, 10));
}
CINDER_APP( QuickTimeSampleApp, RendererGl, QuickTimeSampleApp::prepareSettings );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment