2

私は次のMPMoviePlayerControllerように初期化されたを持っています:

//Code in my UIViewController
@property (nonatomic, strong) UIView *myVideoView;
@property (nonatomic, strong) MPMoviePlayerController *myVideoPlayer;

- (void) initializeVideoPlayer
{
    CGRect frame = CGRectMake(0, 70, self.view.frame.size.width, 200);
    self.myVideoView = [[UIView alloc] initWithFrame:frame];
    [self.view addSubview:self.myVideoView];

    NSURL *videoURL = [NSURL fileURLWithPath:path];

    self.myVideoPlayer = [[MPMoviePlayerController alloc] initWithContentURL:videoURL];
    self.myVideoPlayer.controlStyle = MPMovieControlStyleEmbedded;
    self.myVideoPlayer.shouldAutoplay = YES;
    [self.myVideoPlayer.view setFrame: self.myVideoView.bounds];
    [self.myVideoView addSubview: self.myVideoPlayer.view];

    //Play video
    [self.myVideoPlayer prepareToPlay];
    [self.myVideoPlayer play];

}

私の質問は、ユーザーが電話を横向きに回転させたときにビデオをフルスクリーンで再生し、電話が縦向きのときにフルスクリーンで再生しないようにするにはどうすればよいですか。

以下を追加してみましたUIViewController

- (void) willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
    if(UIInterfaceOrientationIsLandscape(toInterfaceOrientation))
    {
        [self.myVideoPlayer setFullscreen:YES animated:YES];
    }
    else
    {
        [self.myVideoPlayer setFullscreen:NO animated:YES];
    }
}

ただし、これに伴う問題は、プレーヤーがフルスクリーンにwillAnimateRotationToInterfaceOrientationなると、呼び出されなくなることです。したがって、ユーザーが回転して縦向きに戻っても、ビデオはフルスクリーンのままです。

4

2 に答える 2

3

MPMoviePlayerViewControllerの代わりにを使用してみてくださいMPMoviePlayerController。で初期化し、プレーンの場合と同じUIViewControllerようにそのプロパティを使用します。サブクラス化すると、実装などによってデバイスが回転したときに何が起こるかを制御できます。moviePlayerMPMoviePlayerControllerMPMoviePlayerViewControllerwillAnimateRotationToInterfaceOrientation

于 2012-11-28T16:07:38.760 に答える
0

AppDelegate.hの場合:

@property(nonatomic)BOOL allowRotation;

AppDelegate.mで:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    RootViewController * root = [[RootViewController alloc] init];
    self.window.rootViewController = root;

//add two Notification

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(MPVisionVideoNotification:) name:MPMoviePlayerWillEnterFullscreenNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(MPVisionVideoNotification:) name:MPMoviePlayerWillExitFullscreenNotification object:nil];

    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    return YES;
}

- (void) moviePlayerWillEnterFullscreenNotification:(NSNotification*)notification {
    self.allowRotation = YES;
}

- (void) moviePlayerWillExitFullscreenNotification:(NSNotification*)notification {
    self.allowRotation = NO;
}

-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
    if (self.allowRotation) {

        return UIInterfaceOrientationMaskLandscapeRight ;
    }
    return UIInterfaceOrientationMaskPortrait;
}

//this can rotate the windows when to fullscreen state
于 2014-04-11T05:45:11.423 に答える