Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
- (id)init {
if (![NSThread isMainThread]) {
pool = [[NSAutoreleasePool alloc] init];
}
self = [super init];
if(self) {
self.playerView = [[[ofAVFoundationVideoPlayerView alloc] initVideoPlayerView] autorelease];
self.player = [[[AVPlayer alloc] init] autorelease];
[(ofAVFoundationVideoPlayerView *)self.playerView setPlayer:_player];
[_player addObserver:self
forKeyPath:kRateKey
options:NSKeyValueObservingOptionNew
context:nil];
timeObserver = nil;
timeObserverFps = 30;
videoSampleBuffer = nil;
audioSampleBuffer = nil;
videoSampleTime = kCMTimeZero;
videoSampleTimePrev = kCMTimeZero;
audioSampleTime = kCMTimeZero;
synchSampleTime = kCMTimeInvalid;
duration = kCMTimeZero;
currentTime = kCMTimeZero;
volume = 1;
speed = 1;
frameRate = 0;
videoWidth = 0;
videoHeight = 0;
bWillBeUpdatedExternally = NO;
bReady = NO;
bLoaded = NO;
bPlayStateBeforeLoad = NO;
bUpdateFirstFrame = YES;
bNewFrame = NO;
bPlaying = NO;
bFinished = NO;
bAutoPlayOnLoad = NO;
bLoop = NO;
bSeeking = NO;
bSampleVideo = YES;
bSampleAudio = YES;
}
return self;
}
- (void)dealloc {
[(ofAVFoundationVideoPlayerView *)self.playerView setPlayer:nil];
[self.playerView removeFromSuperview];
self.playerView = nil;
if(self.playerItem != nil) {
NSNotificationCenter * notificationCenter = [NSNotificationCenter defaultCenter];
[notificationCenter removeObserver:self
name:AVPlayerItemDidPlayToEndTimeNotification
object:self.playerItem];
[self.playerItem removeObserver:self forKeyPath:kStatusKey];
self.playerItem = nil;
}
[self removeTimeObserverFromPlayer];
[_player removeObserver:self forKeyPath:kRateKey];
self.player = nil;
[_player release];
[self.assetReader cancelReading];
self.assetReader = nil;
self.assetReaderVideoTrackOutput = nil;
self.assetReaderAudioTrackOutput = nil;
self.asset = nil;
if(videoSampleBuffer) {
CFRelease(videoSampleBuffer);
videoSampleBuffer = nil;
}
if(audioSampleBuffer) {
CFRelease(audioSampleBuffer);
audioSampleBuffer = nil;
}
if ([NSThread isMainThread]) {
[super dealloc];
}
else {
[pool drain];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.