views:

1397

answers:

0

Hello SO Friends,

This is my first post at SO. I would like to thank all of the SO users, their contribution have helped me a lot in all of my projects. I am new to the iPhone Application development scene.

Aim of the project is to have a custom interactive User Interface (UI) on top of Movie Player objects (*.mov files on device). The underlying FullScreen MoviePlayers can be more than one and need to switch to different ones based on user Interaction.

I am using cocos2D to achieve the custom interactive UI and effects (for e.g. particle effects on swipe gesture). And I am using Multiple MPMoviePlayerViewController* to play the resident movie files (*.mov) on fullscreen mode (refered to MoviePlayer sample).

Requirement is to switch between movies by switching between default and alternate moviePlayer upon touch detection. Also, the switching should be as smooth as possible.

To achieve smooth switching I am using two moviePlayerViewControllers, each a subview of UIView object in AppController.

Problem a: I am not sure if this is the right way to achieve movie switching.

Problem b: In my current solution. The Default MoviePlayer is rotated in portrait mode, and sometimes the moviePlayer object is not visible. The behaviour is not consistent.

Problem c: The Alternate movie player (object of MPMoviePlayerViewController and added first as subview of UIWindow) rotates on device rotation and behaves properly the Default Movie Player (object of MPMoviePlayerViewController added after) doesn't. Can't think of logical explanation of it. Somewhere I read that MPMoviePlayerViewController creates it's own window and that might be an issue.

    // From AppController.h

    UIWindow *window; // Parent application window
    UIView *viewCocos2D;    // Cocos View
    UIView *viewMovie;      // Default MoviePlayer View
    UIView *viewMovieAlternate;  // Alternate MoviePlayer View


// From AppController.m
// From DidAppFinishLoading
{
... 
 // Init the window
 window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 

        // Init the views (Cocos2d, MOviePlayer and AlternateMOviePlayer)
 viewCocos2D = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
 viewMovie = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
 viewMovieAlternate = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 

 // cocos2d will inherit these values
 [viewCocos2D setUserInteractionEnabled:YES]; 
 [viewCocos2D setMultipleTouchEnabled:YES];


 // create OpenGL view and attach it to a window
 //[[[UIApplication sharedApplication] keyWindow] addSubview:window];
 [[CCDirector sharedDirector] attachInView:viewCocos2D];

 // Default texture format for PNG/BMP/TIFF/JPEG/GIF images
 [CCTexture2D setDefaultAlphaPixelFormat:kCCTexture2DPixelFormat_RGBA8888]; 


 // Create a 
 customMoviePlayerWithUI = [[CustomMoviePlayerWithUI alloc] initWithSuperView:window andMovieView:viewMovie andAlternateView:viewMovieAlternate andSelf:self];
 CCScene *scene = [CCScene node];
 CocosCustomLayer *cocosLayer = [customMoviePlayerWithUI cocosLayer]; 


 [window addSubview:viewMovieAlternate];
 [window addSubview:viewMovie];
 // somehow this order lets cocos2D receive the touch events
 [window addSubview:viewCocos2D]; 


 [scene addChild: cocosLayer];
 [window makeKeyAndVisible];

 [[CCDirector sharedDirector] runWithScene: scene];
 [UIAccelerometer sharedAccelerometer].delegate = self;


 [customMoviePlayerWithUI start];
 [self didRotate:nil];

 ...
}

So the View hierarchy is

Alternate Movie Player View is at bottom Default Movie Player view is next Cocos2D Layer View is on top -- Cocos2D view also receives all of the events.

    // From CustomMoviePlayerWithUI.h
 MPMoviePlayerViewController *moviePlayerView;
 MPMoviePlayerViewController *moviePlayerViewAlternate; 

// These delegates are used frequently to invoke some functions
 AppController* delegateApplication;
 UIView  *delegateSuperWindow;  // Window which contains everything - 
 UIView *delegateView;         // View containing default MoviePlayer
 UIView *delegateViewAlternate;// View containing alternate MoviePlayer

Following is the moviePlayerViewController init code -- basically it allocs and inits two moviePlayerViewController objects and adds them as subview to the Default and Alternate UIView objects from AppController

// From customMoviePlayer.m
// initAndPlayMovie is called from the init of CustomMoviePlayer
- (void)initAndPlayMovie:(UIView *)view andAlternateView:(UIView*) viewMovieAlternate
{
 // Initialize a movie player object with the specified URL
 moviePlayerView = [[MPMoviePlayerViewController alloc] init];
 moviePlayerViewAlternate = [[MPMoviePlayerViewController alloc] init];


 [moviePlayerView shouldAutorotateToInterfaceOrientation:UIInterfaceOrientationLandscapeLeft];
 [moviePlayerViewAlternate shouldAutorotateToInterfaceOrientation:UIInterfaceOrientationLandscapeLeft];

 //if (moviePlayer)
 if (moviePlayerView && moviePlayerViewAlternate)
 {
  [[[moviePlayerView moviePlayer] backgroundView] setBackgroundColor:[UIColor blueColor]];
  [[[moviePlayerViewAlternate moviePlayer] backgroundView] setBackgroundColor:[UIColor redColor]];





  //[moviePlayerView setWantsFullScreenLayout:YES];

  // private API call.. don't use it..
  //[mp setOrientation:UIDeviceOrientationPortrait animated:NO];



  [view addSubview:[moviePlayerView view]];
  [viewMovieAlternate addSubview:[moviePlayerViewAlternate view]];
  //[view bringSubviewToFront:[moviePlayerView view]];

  //[[moviePlayerView moviePlayer] play]; 
 }
}

Thanks for all of your help. Let me know if you need any more details on it.