I. Media Player framework
Video Playback is complicated because Apple encapsulates their processing in the Media Player framework perfectly.
To use the Media Player framework, you must add the MediaPlayer. framework to the project and import <MediaPlayer/MediaPlayer. h> in the source code.
Ii. MPMovePlayerViewControoler class
The Media Player framework contains the MPMovePlayerController class. From SDK3.2, MPMovePlayerViewController is replaced.
MPMovePlayerViewController uses the notification mode to notify the observer that some events are happening. The observer must pay attention to three notifications:
MPMovePlayerContentPreloadDidFinishNotification: the file has been loaded.
MPMovePlayerPlaybackDidFinishNotification: replay completed
MPMovePlayerScalingModeDidChangeNotification: Scaling mode change
3. Video Playback steps
1. the file to be played is encapsulated as a URL
NSString * path = [[NSBundle mainBundle] pathForResource: Mov_FileofType: nil];
NSURL * url = [NSURL fileURLWithPath: path];
2. Use the URL to initialize the MPMovePlayerViewController object
Player = [[MPMoviePlayerViewController alloc] initWithContentURL: url];
3. Use the notification mode to notify the observer as needed
[[Nsicationcenter center defacenter center] addObserver: self selector: @ selector (fileLoaded :)
Name: MPMediaPlaybackIsPreparedToPlayDidChangeNotification object: nil];
4. Use UIViewController (Note: Non-MPMovePlayerViewController) presentMoviePlayerViewControllerAnimated: To play the video.
[Self presentMoviePlayerViewControllerAnimated: player];
5. implement related event listening Methods
-(Void) fileLoaded :( NSNotification *) notification {
NSLog (@ "% s" ,__ FUNCTION __);
}