Skip to content

Instantly share code, notes, and snippets.

@AlexJWayne
Created August 28, 2009 06:07
Show Gist options
  • Select an option

  • Save AlexJWayne/176798 to your computer and use it in GitHub Desktop.

Select an option

Save AlexJWayne/176798 to your computer and use it in GitHub Desktop.
//
// VideoPlayerController.m
// Beezag
//
// Created by Alex Wayne on 8/27/09.
// Copyright 2009 __MyCompanyName__. All rights reserved.
//
#import "VideoPlayerController.h"
@interface VideoPlayerController (Internal)
// just a dummy to provide type info to the compiler
- (double)duration;
@end
@implementation VideoPlayerController
- (id)initWithVideo:(Video*)video {
if (self = [super initWithContentURL:[NSURL fileURLWithPath:video.fileName]] ) {
// Add an observer so we can be told when the movie has finished preloading and playing.
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayBackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:self];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePreloadDidFinish:) name:MPMoviePlayerContentPreloadDidFinishNotification object:self];
}
return self;
}
- (void)prepareCRS:(double)aDuration {
duration = aDuration;
// TODO: implement CRS rendering...
NSLog(@"duration: %f", (float)duration);
}
- (void)moviePlayBackDidFinish:(NSNotification*)notification {
NSLog(@"Movie playback finished.");
}
- (void)moviePreloadDidFinish:(NSNotification*)notification {
NSLog(@"Movie preload finished");
}
// this is called by the internal API when the movie is done loading... we can find the MPItem
// from the user dictionary, and ask it for its duration (internal api)... we need the duration
// to find the halfway point
- (void)_movieDidPreload:sender {
NSDictionary *dict = [sender userInfo];
id item = [dict objectForKey:@"AVController_Item"];
[self prepareCRS:[item duration]];
[(id)super _movieDidPreload:sender];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment