Multimedia play-video play, multimedia-video play

Source: Internet
Author: User
Tags notification center

Multimedia play-video play, multimedia-video play
For video playback, You need to import the framework MediaPlayer. framework into the file # import <MediaPlayer/MediaPlayer. h>

There are two ways to play a video: MPMoviePlayerController. Although the name is controller, It inherits from NSObject and is not a view. It has a view attribute and can set the size.

The other is the video playback View Controller MPMoviePlayerViewController. A full-screen video playback interface is displayed, and the size cannot be changed.

Method 1: MPMoviePlayerController:
MPMoviePlayerController * movie = [[MPMoviePlayerController alloc] init]; _ movie. contentURL = url; _ movie. view. frame = CGRectMake (0, 20,375,550); // Add to window [self. view addSubview: _ movie. view]; // play [_ movie play];

After the video is played, movie. view will not be automatically removed. However, after the video is played, the system will generate a notification of playback completion, so we will create a notification center to obtain it.

// Register the notification and check whether the video has been played. [[nsnotifcenter center defacenter center] addObserver: self selector: @ selector (stopPlay) name: MPMoviePlayerPlaybackDidFinishNotification object: nil]; // notification method-(void) stopPlay {[_ movie. view removeFromSuperview];}
Method 2: MPMoviePlayerViewController:
MPMoviePlayerViewController * playerViewController = [[MPMoviePlayerViewController alloc] modes: url]; // bring up the video player UI mode and play it automatically [self presentViewController: playerViewController animated: YES completion: nil];

After the MPMoviePlayerViewController is played, it will automatically pop up and you do not need to manage it in the notification center.

 

 

Note: The url is a video link, both of which can directly play the network link.

 

 

Related Article

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.