MyViewController
Interface
Imports:#import < MediaPlayer/MediaPlayer.h >#import "MyOverlayView.h"
extern NSString * const OverlayViewTouchNotification' creates a global constant that will be used for touches to the overlay view. Any class importing MyViewController can access this variable.Instance variables:
mMoviePlayer (MPMoviePlayerController)mMovieURL (NSURL)mOverlayView (MyOverlayView)
-(NSURL *)movieURL;-(void)initMoviePlayer;-(IBAction)playMovie:(id)sender;-(void)overlayViewTouches:(NSNotification *)notification;-(IBAction)overlayViewButtonPress:(id)sender;
Implementation
Imports:- #import "MoviePlayerAppDelegate.h"
OverlayViewTouchNotification with the string 'overlayViewTouch'.#pragma is a compiler directive. However the compiler ignores it if #pragma mark is used. #pragma mark helps with the organisation of your methods in the Xcode dropdown list.'
#pragma mark -' divvies up the methods by creating a spacer line while '#pragma mark Movie Player Routines' creates a bold label with the text 'Movie Player Routines'.Movie Player Routines
- (void) moviePreloadDidFinish:(NSNotification*)notification
- (void) moviePlayBackDidFinish:(NSNotification*)notification
- (void) movieScalingModeDidChange:(NSNotification*)notification
These are events. When they are triggered is evident from the names. There is no code inside them.
-(void)initMoviePlayer
- Register
MPMoviePlayerContentPreloadDidFinishNotification(named after the definition in MPMoviePlayerController.h) withNSNotificationCenter. - The movie player object,
mMoviePlayer, is created by allocatingMPMoviePlayerControllerand initialising it withmovieURL. - Register
MPMoviePlayerPlaybackDidFinishNotificationandMPMoviePlayerScalingModeDidChangeNotification, givingmMoviePlayeras the notification sender. - Obtain the
MoviePlayerAppDelegateobject and use its instance variables to setmMoviePlayer. - Register
OverlayViewTouchNotification.
- Play
mMoviePlayer. - Get the application windows in an array.
- Get the movie player window.
- Add
mOverlayViewas the subview of the movie player window.
-(NSURL *)movieURL
- Check
mMovieURLwhether it's null or not. - Passing will return
mMovieURL. - Failing will get the main bundle, look for 'Movie.m4v', check it and convert the path to
NSURLbefore assigning it tomovieURL.
-(void)didReceiveMemoryWarning
-(void)overlayViewTouches:(NSNotification *)notification
-(IBAction)overlayViewButtonPress:(id)sender
Trivial or empty methods.
-(void)dealloc
Remove all registered notifications and release the movie player.
No comments:
Post a Comment