2 Review IOS video Core Video Framework Core Media Framework How to play video by xcodeAVPlayerController classMPMoviePlayerController class
3 Core Video FrameworkAs the name implies, this framework is used for video processing and is primarily responsible for providing video buffering support. The main data type that we are interested in from this framework is CVImageBufferRef, which will be used to access the buffered picture data from our video stream. We’ll also use many different CoreVideo functions, including CVPixelBufferGetBytesPerRow()and CVPixelBuffe rLockBaseAddress(). Anytime you see a “CV” prepended to a data type or function name, you’ll know that it came from CoreVideo.
4 Core Media FrameworkCore Media provides the low-level support upon which the AV Foundation framework (added in the last tutorial) is built. We’re really just interested in the CMSampleBufferRef data type and theCMSampleBufferGetImageBuffer() func tion from this framework.
5 Using Objective-C observers: The observer pattern is not used very often while doing Cocos2d programming, but it is a powerful mechanism and it is the recommended way of knowing when your video has finished playback.
6 Movie file format:According to Apple documentation it is recommended that you compress your movies using H.264/MPEG-4 for video, AAC audio and one of the following file formats: MOV, MP4, MPV, 3GP.It is also recommended that your movies be no larger than 640x480 and run no faster than 30 FPS.For more information please consult official Apple iOS SDK documentation.
7 How to play video(AVPlayer) This is the initialization for the player
8 How to play video(AVPlayer) This is the code that plays the video
9 How to play video(AVPlayer) The code to select the clip to be played
10 How to play video(AVPlayer) And last the gesture action
11 An Overview of the MPMoviePlayerController Class It is initialized with the URL of the media to be played (either a path to a local movie file on the device or the URL of network based media). The movie player view is added as a subview of the current view, configured using a variety of properties and then displayed to the user. The playback window can run in a full screen mode, or embedded in an existing view.
12 An Overview of the MPMoviePlayerController Class The MPMoviePlayerController class also employs the target-action model for notifying the application of events such as the movie starting, finishing, being paused, entering and leaving full screen mode etc.
13 Supported Video Formats The MPMoviePlayerController class supports the playback of movies of type .mov, .mp4, .mpv and .3gp. In terms of compression, the class supports H.264 Baseline Profile Level 3.0 and MPEG-4 Part 2 video.
14 Playing Video(MPMoviePlayerController) the video is played to the user when the button is touched by the user. The code for the method should be placed in the movieViewController.m file as follows:
15 Playing Video(MPMoviePlayerController) The playButton action method declared that when the movie has finished playing the movie player object is to call a method named moviePlaybackDidFinish. It is the responsibility of this method to cancel the notification, remove the movie player interface from display and release the memory allocated to it. Edit the movieViewController.m file and add this method as follows: