Created
July 8, 2011 12:22
-
-
Save hartbit/1071714 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
| // | |
| // LaSouris2VideoPageViewController.m | |
| // iConte | |
| // | |
| // Created by David Hart on 7/7/11. | |
| // Copyright 2011 hart[dev]. All rights reserved. | |
| // | |
| #import "LaSouris2VideoPageViewController.h" | |
| @implementation LaSouris2VideoPageViewController | |
| @synthesize topView = _topView; | |
| @synthesize player = _player; | |
| @synthesize thumbnailView = _thumbnailView; | |
| #pragma mark - Lifecycle | |
| - (void)viewDidUnload | |
| { | |
| [self setTopView:nil]; | |
| [self setPlayer:nil]; | |
| [self setThumbnailView:nil]; | |
| [super viewDidUnload]; | |
| } | |
| - (void)dealloc | |
| { | |
| [self setTopView:nil]; | |
| [self setPlayer:nil]; | |
| [self setThumbnailView:nil]; | |
| [super dealloc]; | |
| } | |
| #pragma mark - Properties | |
| - (UIView*)topView | |
| { | |
| if (_topView == nil) | |
| { | |
| UIView* imageView = [[[self view] subviews] objectAtIndex:0]; | |
| CGRect topFrame = [imageView frame]; | |
| [imageView removeFromSuperview]; | |
| UIView* topView = [[UIView alloc] initWithFrame:topFrame]; | |
| [[self view] addSubview:topView]; | |
| [self setTopView:topView]; | |
| [topView release]; | |
| } | |
| return _topView; | |
| } | |
| - (MPMoviePlayerController*)player | |
| { | |
| if (_player == nil) | |
| { | |
| MPMoviePlayerController* player = [[MPMoviePlayerController alloc] init]; | |
| [player setControlStyle:MPMovieControlStyleNone]; | |
| [player setInitialPlaybackTime:0]; | |
| [player setShouldAutoplay:NO]; | |
| [[player view] setFrame:[[self topView] bounds]]; | |
| [[player view] setUserInteractionEnabled:NO]; | |
| [[self topView] addSubview:[player view]]; | |
| [self setPlayer:player]; | |
| [player release]; | |
| } | |
| return _player; | |
| } | |
| - (void)setPlayer:(MPMoviePlayerController*)player | |
| { | |
| if (player != _player) | |
| { | |
| if (_player != nil) | |
| { | |
| [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:_player]; | |
| } | |
| [_player release]; | |
| _player = [player retain]; | |
| if (_player != nil) | |
| { | |
| [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playbackFinished:) name:MPMoviePlayerPlaybackDidFinishNotification object:_player]; | |
| } | |
| } | |
| } | |
| - (UIImageView*)thumbnailView | |
| { | |
| if (_thumbnailView == nil) | |
| { | |
| UIImageView* thumbnailView = [[UIImageView alloc] initWithFrame:[[self topView] bounds]]; | |
| [[self topView] addSubview:thumbnailView]; | |
| [self setThumbnailView:thumbnailView]; | |
| [thumbnailView release]; | |
| } | |
| return _thumbnailView; | |
| } | |
| #pragma mark - Public Methods | |
| - (void)playbackFinished:(NSNotification*)notification | |
| { | |
| } | |
| #pragma mark - UIViewController Methods | |
| - (void)viewWillAppear:(BOOL)animated | |
| { | |
| [super viewWillAppear:animated]; | |
| [[self player] prepareToPlay]; | |
| UIImage* thumbnail = [[self player] thumbnailImageAtTime:0 timeOption:MPMovieTimeOptionNearestKeyFrame]; | |
| [[self thumbnailView] setImage:thumbnail]; | |
| } | |
| - (void)viewDidAppear:(BOOL)animated | |
| { | |
| [super viewDidAppear:animated]; | |
| [[self thumbnailView] setHidden:YES]; | |
| [[self thumbnailView] setImage:nil]; | |
| } | |
| - (void)viewWillDisappear:(BOOL)animated | |
| { | |
| [[self player] pause]; | |
| NSTimeInterval currentTime = [[self player] currentPlaybackTime]; | |
| UIImage* thumbnail = [[self player] thumbnailImageAtTime:currentTime timeOption:MPMovieTimeOptionExact]; | |
| [[self thumbnailView] setImage:thumbnail]; | |
| [[self thumbnailView] setHidden:NO]; | |
| [[[self player] view] removeFromSuperview]; | |
| [super viewWillDisappear:animated]; | |
| } | |
| @end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment