Created
August 28, 2009 06:07
-
-
Save AlexJWayne/176798 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // 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