First on the effect chart
Realize the idea
The main idea is to use a controller to play the video carrier, and then let the controller as a root view, after the video playback is done then what to do.
If you don't say more, let's put the code right here.
First create a new controller AnimationViewController
in the controller to create a new attribute moviePlayer
, remember to first introduce system library<MediaPlayer/MediaPlayer.h>
@property (nonatomic, strong) MPMoviePlayerController *movieplayer;
Setting moviePlayer
I was set directly in lazy loading
-(MPMoviePlayerController *) movieplayer{
if (!_movieplayer) {
_movieplayer = [[MPMoviePlayerController alloc ]init];
[_movieplayer.view setFrame:self.view.bounds];
Set AutoPlay
[_movieplayer setshouldautoplay:no];
Set source type because the new feature is generally playing local small video, set the source type to file
_movieplayer.moviesourcetype = mpmoviesourcetypefile;
Cancel control view such as: Play pause etc
_movieplayer.controlstyle = mpmoviecontrolstylenone;
[Self.view Addsubview:_movieplayer.view];
Listener playback Complete
[[Nsnotificationcenter defaultcenter]addobserver:self selector: @selector (playfinsihed) Name: Mpmovieplayerplaybackdidfinishnotification Object:nil];
}
return _movieplayer;
}
The .h
path to the video is then exposed in, and moviePath
an end playback is blockplayFinished
required.
AnimationViewController
In the same way, after all, there is nothing, and then we go to AppDelegate
declare a AnimationViewController
property
-(Animationviewcontroller *) animationviewcontroller{
if (!_animationviewcontroller) {
_ Animationviewcontroller = [[Animationviewcontroller alloc]init];
Set local video path
_animationviewcontroller.moviepath = [[NSBundle mainbundle] pathforresource:@ "V" oftype:@ "mp4"];
_animationviewcontroller.playfinished = ^{
Uinavigationcontroller *rootnav = [[Uinavigationcontroller alloc] Initwithrootviewcontroller:[[viewcontroller alloc] init];
[UIApplication Sharedapplication].keywindow.rootviewcontroller = Rootnav;}
;
}
return _animationviewcontroller;
}
And then in AppDelegate
the startup method to set this controller as the root view
-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) launchOptions {
Self.window = [[UIWindow alloc]initwithframe:[uiscreen mainscreen].bounds];
Self.window.rootViewController = Self.animationviewcontroller;
[Self.window makekeyandvisible];
Return YES
}
Summarize
Here to say, at first I use this path but has been empty, and then I added a name for the resource folder put the MP4 into the good, the above is the entire content of this article, the need for friends can refer to reference.