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