这是我在 SO 的第一篇文章。我要感谢所有 SO 用户,他们的贡献在我所有的项目中帮助了我很多。我是 iPhone 应用程序开发领域的新手。
该项目的目标是在电影播放器对象(设备上的 *.mov 文件)之上有一个自定义的交互式用户界面 (UI)。底层的 FullScreen MoviePlayers 可以不止一个,需要根据用户交互切换到不同的。
我正在使用 cocos2D 来实现自定义交互 UI 和效果(例如滑动手势上的粒子效果)。我正在使用 Multiple MPMoviePlayerViewController
* 在全屏模式下播放常驻电影文件 (*.mov)(参考 MoviePlayer 示例)。
要求是通过在检测到触摸时在默认和备用电影播放器之间切换来在电影之间切换。此外,切换应尽可能平滑。
为了实现平滑切换,我使用了两个moviePlayerViewControllers
,每个都是UIView
AppController 中对象的子视图。
问题a:我不确定这是否是实现电影切换的正确方法。
问题 b:在我目前的解决方案中。DefaultMoviePlayer
在纵向模式下旋转,有时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];
...
}
所以视图层次结构是
备用电影播放器视图在底部 默认电影播放器视图在下一个 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];
}
}
感谢您所有的帮助。如果您需要更多详细信息,请告诉我。