Multimedia playback----Video playback

Source: Internet
Author: User
Tags notification center

Video playback needs to import frame mediaplayer.framework import #import in file <MediaPlayer/MediaPlayer.h>

There are two ways to play video, one is MPMoviePlayerController, although the name is controller, but he inherits from NSObject, not the view, he has one view property, can set the size.

The other is the video playback view Controller Mpmovieplayerviewcontroller, which pops up a full-screen video playback interface and does not support changing the size.

Method One: MPMoviePlayerController:
MPMoviePlayerController  *movie=[[MPMoviePlayerController alloc]init];    _movie.contenturl=url;    _movie.view.frame=cgrectmake (0-375550);     // Add to Window     [Self.view Addsubview:_movie.view];     // Play    [_movie play];

When the video is finished, Movie.view will not be removed automatically. But after the video is played, a notification is generated, so we set up a notification center to get it.

// Registration notification to detect if video playback is complete    Object : nil]; // Notification Method -(void) stopplay{    [_movie.view Removefromsuperview];}
Method Two: Mpmovieplayerviewcontroller:
Mpmovieplayerviewcontroller *playerviewcontroller=[[Mpmovieplayerviewcontroller Alloc]initWithContentURL: URL]; // pops the video player interface Modal and automatically plays [Self Presentviewcontroller:playerviewcontroller animated:yes completion:nil];

Mpmovieplayerviewcontroller will automatically eject after playback, do not need to notify the center management.

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

Multimedia playback----Video playback

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.