Saturday, June 21, 2014

Movie Playing using MPMoview/ViewController

Playing the movie using the MPMoviewPlayerController is easy. 
A Movie player (of type MPMoviePlayerController) manages the playback of a movie from a file or a network stream. Playback occurs in a view owned by the movie player and takes place either fullscreen or inline. You can incorporate a movie players view into a view hierarchy owned by an app or use an MPMOviewPlayerViewControler object to manage the presentation on behalf of the app

Moview players (iOS 4.3 and later) supports wireless movie playback to Airplay-enabled hardware such as apple TV. The movie player presents a control that allows the user to choose AirPlay-enabled  hardware for playback when such hardware is in range. Starting from iOS 5.0, the AirPlay playback is enabled by default. To disable AirPlay in the app, set the allowsAirPlay property to NO. 

This class supports programmatic control of Moview playback, and user-based control via buttons supplied by the movie player. You can control most aspects of playback programmatically using the methods and properties of the MPMediaPlayback protocol, to which this class conforms. The methods and properties of that protocol let you start and stop playback, seek forward and backward through movie's content, and even change the playback rate. In addition, the controlStype property of this class lets you display a set of standard system controls that allow user to manipulate the playback. 

To facilitate creation of video bookmarks or chapter links for a long movie, MPMoviewPlayerController class defines methods for generateing thumbnail images at specific times within a movie. An app can request a single thumbnail using the thumbnailImageAtTime:timeOption: method or multiple thumbnail images using the requestThumbnaimimagesATTimes:timeopton: method


Below few lines will start the playing. 

_moviewPlayer =[ [MPMoviewPlayerController alloc]initWithContentURL:];
_moviePlayer.controlStyle = MPMoviewControlStyleDefault; 
_moviePlayer.autoPlay = YES;
[self.view addSubView:_moviePlayer.view];
[_moviePlayer setFullScreem:YES animated:YES];

We can get notifications on the status of media playing like in the notes below 

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlaybackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object_moviePlayer];

Below are the Movie Player Notifications available to the app

- When the movie player begins playing, is paused, or begins seeing forward or backward
- When Airplay starts or ends 
- When scaling mode of the movie changes 
- When the movies enters of exits full screen mode
- When the load state for network based movies changes 
- When meta-information about the movies itself becomes available

The supported file formats are .mov, mp4, .mpv and .3gp and using one of the following compression standards 

- H.264 baseline profile level 3.0 video, upto 640x480 at 30fps (The baseline profile doesn't support B frames) 
- MPEG-4 Part 2 video (Simple profile)

IF you use this class to play audio files, it displays a white screen with a QuickTime logo while the audio plays. For audio files, this class supports AAC-LC audio at  up to 48KHz, and MP3 (MPEG-1 audio layer 3) upto 48Khz, stereo audio. 


No comments:

Post a Comment