IOS: Video Playback

Source: Internet
Author: User

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 __);

}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.