ios - Call MPMoviePlayerViewController in app delegate -
i using story board in app. using storyboard views connected new thing want is,
when splash screen goes down, want show 3 sec video every time user opens app.
i know how load video viewcontroller, following code used launch video.
- (void)showvideo { [super viewdidload]; // additional setup after loading view. nsstring *path = [[nsbundle mainbundle] pathforresource:@"video" oftype:@"mp4"]; nsurl *url = [nsurl fileurlwithpath:path]; nslog(@"video path :- %@",url); videocontroller = [[mpmovieplayerviewcontroller alloc] initwithcontenturl:url]; videocontroller.movieplayer.controlstyle = mpmoviecontrolstylenone; [self presentmovieplayerviewcontrolleranimated:videocontroller]; [videocontroller.movieplayer play]; [[nsnotificationcenter defaultcenter] addobserver:self selector:@selector(movieplaybackdidfinish:) name:mpmovieplayerplaybackdidfinishnotification object:videocontroller]; } - (void) movieplaybackdidfinish:(nsnotification*)_notification { [[nsnotificationcenter defaultcenter] removeobserver:self name:mpmovieplayerplaybackdidfinishnotification object:nil]; [videocontroller.view removefromsuperview]; [videocontroller.movieplayer stop]; videocontroller = nil; [self.view removefromsuperview]; }
but when use code in rootviewcontroller app crashes saying
attempt present <mpmovieplayerviewcontroller:> on <dashbaordvc:> view not in window hierarchy
but when use same code in other demo app using navigation controller (no storyboard) works fine. in app story board used, crashes.
also tried
[self.navigationcontroller pushviewcontroller:self.videocontroller animated:no];
then thought of adding code in appdelegate file , calling method applicationdidfinishlaunching
but didn't help. can guide me.... same how add mpmovieplayerviewcontroller
in app delegate.
i think can mpmovieplayercontroller. try following code
nsstring *path = [[nsbundle mainbundle] pathforresource:@"video" oftype:@"mp4"]; nsurl *url = [nsurl fileurlwithpath:path]; videoplayer = [[mpmovieplayercontroller alloc] init]; [videoplayer.view setframe:cgrectmake(0.0, viewtopbar.frame.size.height,[uiscreen mainscreen].bounds.size.width, [uiscreen mainscreen].bounds.size.height - (viewtopbar.frame.size.height + 50.0))]; [videoplayer setmoviesourcetype:mpmoviesourcetypefile]; [videoplayer setcontenturl:url]; [videoplayer setcontrolstyle:mpmoviecontrolstyleembedded]; [videoplayer setscalingmode:mpmoviescalingmodenone]; [videoplayer preparetoplay]; [[nsnotificationcenter defaultcenter] addobserver:self selector:@selector(movieplaybackdidfinish:) name:mpmovieplayerplaybackdidfinishnotification object:videoplayer]; [self.view addsubview:videoplayer.view]; [videoplayer play];
and if dont want full screen used this
[videoplayer setcontrolstyle:mpmoviecontrolstylenone];
Comments
Post a Comment