Frames that need to be imported
#import <MediaPlayer/MediaPlayer.h>
Mediaplayer.framework
Mpmovieplayerviewcontroller:
Open Network Video:
-(void) Openmovie
{
Mpmovieplayerviewcontroller *movie = [[mpmovieplayerviewcontrolleralloc]initwithcontenturl:[nsurlurlwithstring:@] Video network Address "]";
[Movie.movieplayer Preparetoplay];
[Self presentmovieplayerviewcontrolleranimated:movie];
[Movie.moviePlayersetControlStyle:MPMovieControlStyleFullscreen];
[Movie.viewsetbackgroundcolor:[uicolorclearcolor]];
[Movie.view SetFrame:self.view.bounds];
[[Nsnotificationcenterdefaultcenter]addobserver:self
Selector: @selector (moviefinishedcallback:)
Name:mpmovieplayerplaybackdidfinishnotification
Object:movie.moviePlayer];
}
-(void) Moviefinishedcallback: (nsnotification*) notify{
The video is finished or the Done button under presentmovieplayerviewcontrolleranimated is clicked to respond to the notification.
mpmovieplayercontroller* Themovie = [Notifyobject];
[[Nsnotificationcenterdefaultcenter]removeobserver:self
Name:mpmovieplayerplaybackdidfinishnotification
Object:themovie];
[selfdismissmovieplayerviewcontrolleranimated];
}
To open a local video:
-(void) Openmovie
{
NSString *url = [[nsbundlemainbundle]pathforresource:@ "img_0322" oftype:@ "mp4"];
Mpmovieplayerviewcontroller *playerviewcontroller = [[mpmovieplayerviewcontrolleralloc]initwithcontenturl:[ Nsurlfileurlwithpath:url]];
[[Nsnotificationcenterdefaultcenter]addobserver:selfselector: @selector (moviefinishedcallback:)
Name:mpmovieplayerplaybackdidfinishnotification
Object:[playerviewcontrollermovieplayer]];
[Self.view AddSubview:playerViewController.view];
MPMoviePlayerController *player = [Playerviewcontrollermovieplayer];
[Playerplay];
}
-(void) Moviefinishedcallback: (nsnotification*) anotification {
MPMoviePlayerController *player = [Anotificationobject];
[[Nsnotificationcenterdefaultcenter]removeobserver:selfname:mpmovieplayerplaybackdidfinishnotificationobject: Player];
[Playerstop];
[Player.viewremovefromsuperview];
}
iOS video playback Mpmovieplayerviewcontroller