0

In my application, I would like to show a movie on the first screen (the first time user opens an application) and when movie is finished running, the login screen should show.

I have two questions:

  1. The way I am trying to do it, is to show the video on a separate controller and when movie is finished, perform segue to the login controller. Is this the correct way to do it?

  2. I am doing performSegueWithIdentifier when I receive MPMoviePlayerPlaybackDidFinishNotification. The problem is that nothing happens. The video remains on the screen and the controller is not changed. I don't see any errors in the console. Is there a problem to perform segue from NSNotificationCenter notification?

John Willemse
  • 6,608
  • 7
  • 31
  • 45
Erik Sapir
  • 23,209
  • 28
  • 81
  • 141
  • Check if you are actually doing it on the main thread. If not, try dispatch_async(dispatch_get_main_queue(), ^{//your code here//}); – Tcharni Mar 11 '14 at 07:39
  • I am - performSegueWithIdentifier is done on the main thread, as a result of MPMoviePlayerPlaybackDidFinishNotification – Erik Sapir Mar 11 '14 at 07:41
  • In that case, I think it is a problem with the program control. Did you set up and implement the delegate correctly? Perhaps set up breakpoints at MPMoviePlayerPlaybackDidFinishNotification function, to see if program control does pass there. – Tcharni Mar 11 '14 at 07:45
  • Yes - MPMoviePlayerPlaybackDidFinishNotification is called and even the segue is called. In fact, if i move the performSegueWithIdentifier to viewDidLoad and now showing video at all, the segue works – Erik Sapir Mar 11 '14 at 07:47
  • Try putting the performSegueWithIdentifier inside dispatch_async(dispatch_get_main_queue(), ^{//your code here//}); I believe it should solve your problem. – Tcharni Mar 11 '14 at 07:48
  • You could use CCDirector library in your login view, and you will play a video with cocos2d in your LoginView. I use it in a lot of projects and it works very nice – Fran Martin Mar 11 '14 at 07:57
  • @Tcharni dispatch_async(dispatch_get_main_queue() did not work - still nothing happens. – Erik Sapir Mar 11 '14 at 08:01
  • @SonGoku68 So what you saying is that you use a single controller with two views? – Erik Sapir Mar 11 '14 at 08:01
  • Yes, use your loginViewController for to load in a view CCGLView the video. This view(CCGLView class) should be in front of all views in your LoginViewController. I will answer you with my solution – Fran Martin Mar 11 '14 at 08:06

2 Answers2

1

A possible way to do this would be to reverse the viewController hierarchy.

  • Start off with the loginViewController, and have a flag that determines whether it is the first login. If that is the case, then have an introVideoViewController presented over the loginViewController with the loginViewController as its delegate.
  • Place the code to initiate and present your introVideoViewController in the viewDidLoad of loginViewController, so it appears that the app has directly started in the introVideoViewController
  • With MPMoviePlayerPlaybackDidFinishNotification, perform something like: [self.delegate introVideoDidFinishPlaying];. This will transfer control back to loginViewController, which can then dismiss the presentedViewController.

I'm not familiar how to do it with storyboards, but this approach definitely works with nibs.

Tcharni
  • 644
  • 1
  • 6
  • 17
  • It actually sounds good. Would i be able to use animation - i would like to dismiss the video with fade out effect – Erik Sapir Mar 11 '14 at 08:15
  • Yes of course. Although you may have to modify the code to include UIView animations. This question gives a brief overview on block UIView animation statements: http://stackoverflow.com/questions/3126833/what-are-block-based-animation-methods-in-iphone-os-4-0 – Tcharni Mar 11 '14 at 08:18
1

As I commented, in your .h file of your loginViewController...

#import <UIKit/UIKit.h>
#import "cocos2d.h"
#import "cocos2d.h"

@interface VPViewController : UIViewController<CCDirectorDelegate>

@property (nonatomic, strong) IBOutlet CCGLView *glView;

In your .m loginViewController...

@synthesize glView=glView_;

In your viewDidLoad method

CGRect glViewFrame = self.glView.frame;
CGRect screenBounds = [[UIScreen mainScreen] bounds];
if (screenBounds.size.height == IPHONE_5_SCREEN_SIZE) {
    glViewFrame.size.height = 578;
}else{
    glViewFrame.size.height = 490;
}
[self.glView setFrame:glViewFrame];

CCDirector *director = [CCDirector sharedDirector];
[director setDisplayStats:NO];
[director setView:glView_];

// Enables High Res mode (Retina Display) on iPhone 4 and maintains low res on all other devices
if( ! [director enableRetinaDisplay:YES] )
    CCLOG(@"Retina Display Not supported");

// turn on multiple touches
[glView_ setMultipleTouchEnabled:YES];

CCScene *scene = [CCScene node];
glClearColor(0,0,0,0);

[scene setRotation:90.0f];

if([director enableRetinaDisplay:YES] && [self returnMaxTextureSize] == 2048){

    // this is a device with 2.0 scale factor and a max texture size of 2048 pixels
    NSLog(@"2048 only");
    [scene setScale:2.0f];

}else{

    [scene setScale:1.5f];

}

CCSprite * bg = [CCSprite spriteWithFile:@"login_background_white.png"];
[bg setRotation:-90.0f];
[bg setScale:0.8f];
[bg setPosition:ccp(155, 270)];
[scene addChild:bg z:-1];

[scene addChild: [VPAnimation node]];

[director pushScene:scene];
[director startAnimation];

And finally, in your xib...

enter image description here

Fran Martin
  • 2,369
  • 22
  • 19