0

我的问题如下:正确管理应用程序状态。我有几个实现 MPMoviePlayerViewcontroller 的 xib。当应用程序回到前台时,轻量级(大约 100kb 的重量)循环视频会自动播放(我已经处理了应用程序状态,因此可以正常工作)。

在第一个 Xib 中,视频在回到前台时立即播放。第二个 Xib 需要更多时间。第 3 个 Xib 需要更多时间才能继续自动播放,而从第 4 个 Xib 开始,自动播放需要大约 10 秒。当应用程序从后台返回到前台时,黑屏需要很长时间才能开始自动播放。好像一个 Xib 会影响另一个。

我在每个 xib 中都执行相同的代码,并且随着我的前进,播放器继续自动播放需要更长的时间。请注意,我在播放器上方覆盖按钮以返回或下一步。如何解决前面解释的滞后?

AppDelegate.h

- (void)applicationWillResignActive:(UIApplication *)application
{
    [[NSNotificationCenter defaultCenter] postNotificationName:@"WillResignActive" object:nil];
}
- (void)applicationDidEnterBackground:(UIApplication *)application
{
    [[NSNotificationCenter defaultCenter] postNotificationName:@"WillResignActive" object:nil];
}
- (void)applicationWillEnterForeground:(UIApplication *)application
{
    [[NSNotificationCenter defaultCenter] postNotificationName:@"WillEnterForeGround" object:nil];
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{
    [[NSNotificationCenter defaultCenter] postNotificationName:@"DidBecomeActive" object:nil];
}

ViewController1.h

@synthesize playerController;

-(IBAction)next
{
two *back = [[two alloc]initWithNibName:@"two" bundle:Nil];
back.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentViewController:back animated:YES completion:nil ];

[back release];

}

- (void)viewDidLoad{
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"MyFile" ofType:@"mov"]];
playerController = [[MPMoviePlayerViewController alloc]initWithContentURL:url];
[self presentMoviePlayerViewControllerAnimated:playerController];
[self.view insertSubview:playerController.view atIndex:0];
playerController.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
playerController.moviePlayer.controlStyle = MPMovieControlStyleNone;
playerController.moviePlayer.scalingMode = MPMovieScalingModeFill;
playerController.moviePlayer.repeatMode = MPMovieRepeatModeOne;
playerController.moviePlayer.view.userInteractionEnabled = NO;
playerController.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(AppDidBecomeActive) name:@"DidBecomeActive" object:nil];;

[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(EnteredBackground) name:@"WillResignActive" object:nil];;
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(EnteredForeground) name:@"WillEnterForeGround" object:nil];;
[playerController.moviePlayer prepareToPlay];
[playerController.moviePlayer prepareToPlay];
[playerController.moviePlayer play];


}

-(void)AppDidBecomeActive{
if(playerController.moviePlayer.playbackState == MPMoviePlaybackStateInterrupted || playerController.moviePlayer.playbackState == MPMoviePlaybackStateStopped || playerController.moviePlayer.playbackState == MPMoviePlaybackStatePaused)
{
    [playerController.moviePlayer play];
}
}

-(void)EnteredBackground
{        [playerController.moviePlayer pause];




}

-(void)EnteredForeground
{        [playerController.moviePlayer play];

}
4

0 回答 0