Multiple splash of MPMoviePlayerViewController full-text update and switching issue - full-screen view does not autorotate and minor similar issues
This is my first post on SO. I would like to thank all SO users, their contributions have helped me a lot in all my projects. I am new to iPhone application development.
The goal of the project is to create a custom interactive user interface (UI) on top of Movie Player objects (* .mov files on the device). The underlying FullScreen MoviePlayers can be more than one and should switch to different ones based on user interaction.
I am using cocos2D to achieve custom interactive UI and effects (for example, particle gesture effects). And I am using Multiple MPMoviePlayerViewController
* to play resident movie files (* .mov) full screen (see MoviePlayer sample).
The requirement is to switch between movies, switching between standard and alternative MoviePlayer when touch is detected. In addition, the connection should be as smooth as possible.
To achieve a smooth switching, I use two moviePlayerViewControllers
, each of which is a subclass of an object UIView
in AppController.
Problem a: I'm not sure if this is the correct way to switch videos.
Objective b: In my current solution. MoviePlayer
Rotates in portrait by default , and sometimes the moviePlayer is not displayed. The behavior is inconsistent.
Problem c: Alternate video player (object MPMoviePlayerViewController
and added first as UIWindow sub) rotates on device rotation and behaves correctly by default Movie Player (object MPMoviePlayerViewController
added after) does not. Can't think of a logical explanation for this. I read somewhere that MPMoviePlayerViewController
creates a custom window and that might be the problem.
// 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
Alternative Movie Viewer at the bottom By default, the Cocos2D Layer View is at the top - the Cocos2D view also accepts all 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
Below is the initialization code for moviePlayerViewController - basically it selects and inserts two moviePlayerViewController objects and adds them as subordinates of 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 your help. Let me know if you need any details about this.
a source to share
No one has answered this question yet
Check out similar questions: