Skip to content

Instantly share code, notes, and snippets.

@lab101
Created March 14, 2016 16:38
Show Gist options
  • Save lab101/bacbe237139ddee89249 to your computer and use it in GitHub Desktop.
Save lab101/bacbe237139ddee89249 to your computer and use it in GitHub Desktop.
AVPlayerLayer in Cinder
#include "cinder/app/RendererGl.h"
#include "cinder/gl/gl.h"
#include "cinder/app/cocoa/AppCocoaTouch.h"
#include "cinder/app/cocoa/CinderViewCocoaTouch.h"
#import <AVFoundation/AVFoundation.h>
using namespace ci;
using namespace ci::app;
using namespace std;
class TalentenAppApp : public AppCocoaTouch {
AVPlayerLayer *layer;
AVPlayer *player;
public:
static void prepareSettings( AppCocoaTouch::Settings *settings );
void setup() override;
void mouseDown( MouseEvent event ) override;
void update() override;
void draw() override;
};
void TalentenAppApp::prepareSettings( AppCocoaTouch::Settings *settings )
{
}
void TalentenAppApp::setup()
{
NSURL* url = [[NSBundle mainBundle] URLForResource:@"assets/intro_ipad" withExtension:@"mp4"];
player = [AVPlayer playerWithURL:url]; //
// [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playerItemDidReachEnd:) name:AVPlayerItemDidPlayToEndTimeNotification];
layer = [AVPlayerLayer layer];
player.actionAtItemEnd = AVPlayerActionAtItemEndNone;
[layer setPlayer:player];
[layer setFrame:CGRectMake(0, 0, 1024, 768)];
// [layer setBackgroundColor:[UIColor redColor].CGColor];
[layer setVideoGravity:AVLayerVideoGravityResizeAspectFill];
CinderViewCocoaTouch *cinderView = reinterpret_cast<CinderViewCocoaTouch *>( getWindow()->getNative() ) ;
[cinderView.layer addSublayer:layer];
[player play];
}
void TalentenAppApp::mouseDown( MouseEvent event )
{
}
void TalentenAppApp::update()
{
}
void TalentenAppApp::draw()
{
gl::clear( Color( 0, 0, 0 ) );
}
CINDER_APP_COCOA_TOUCH( TalentenAppApp, RendererGl( RendererGl::Options().msaa( 0 ) ), TalentenAppApp::prepareSettings )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment