0

私の問題は次のとおりです。アプリの状態を適切に管理します。MPMoviePlayerViewcontroller を実装するいくつかの xib があります。アプリがフォアグラウンドに戻ると、ライト (約 100kb の重さ) ループ動画が自動再生されます (アプリの状態は既に処理されているため、正常に動作します)。

最初の Xib では、フォアグラウンドに戻るとすぐにビデオが再生されます。2 番目の Xib には時間がかかります。3 番目の Xib では、自動再生を続行するのにさらに時間がかかり、4 番目の Xib 以降では、自動再生に 10 秒ほどかかります。アプリがバックグラウンドからフォアグラウンドに戻ったとき、自動再生を開始するまで黒い画面で多くの時間がかかります。あたかも 1 つの Xib が他の 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