多个MPMoviePlayerViewController全屏电影init&切换问题 - 全屏视图不会自动旋转和轻微的类似问题

时间:2010-05-17 16:12:20

标签: objective-c cocos2d-iphone mpmovieplayercontroller movieplayer

这是我在SO的第一篇文章。我要感谢所有SO用户,他们的贡献在我的所有项目中帮助了我很多。我是iPhone应用程序开发领域的新手。

该项目的目标是在Movie Player对象(设备上的* .mov文件)之上设置自定义交互式用户界面(UI)。底层的FullScreen MoviePlayers可以是多个,需要根据用户交互切换到不同的。

我正在使用cocos2D来实现自定义交互式UI和效果(例如,对滑动手势的粒子效果)。我正在使用多个MPMoviePlayerViewController *在全屏模式下播放常驻电影文件(* .mov)(参考MoviePlayer示例)。

要求在触摸检测时通过在默认和备用moviePlayer之间切换来切换动画。此外,切换应尽可能顺利。

为了实现平滑切换,我使用两个moviePlayerViewControllers,每个都是AppController中UIView对象的子视图。

问题a:我不确定这是否是实现电影切换的正确方法。

问题b:在我目前的解决方案中。默认MoviePlayer以纵向模式旋转,有时无法看到moviePlayer对象。行为不一致。

问题c:替代电影播放器​​(MPMoviePlayerViewController的对象并首先添加为UIWindow的子视图)在设备旋转时旋转并且正常运行默认电影播放器​​(之后添加的MPMoviePlayerViewController对象)吨。想不出它的逻辑解释。在某处,我读到MPMoviePlayerViewController创建了自己的窗口,这可能是一个问题。

    // 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];

 ...
}

所以View层次结构是

备用电影播放器​​视图位于底部 默认电影播放器​​视图是下一个 Cocos2D图层视图位于顶部 - Cocos2D视图也接收所有事件。

    // 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

以下是moviePlayerViewController初始化代码 - 基本上它分配并插入两个moviePlayerViewController对象,并将它们作为子视图添加到AppController中的Default和Alternate UIView对象

// 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]; 
 }
}

感谢您的所有帮助。如果您需要更多详细信息,请与我们联系。

0 个答案:

没有答案