3

MPMoviePlayerController をフルスクリーンで表示したい。横向きでも構いません。MPMoviePlayerController は、縦表示でのみ使用できます。これは試した私のコードです:

MPMoviePlayerController を作成します。

    NSURL *movieURL = [NSURL URLWithString:previewString];
    movieController = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];


    [movieController.view setFrame:CGRectMake(10,130, 275 , 150)];
    movieController.view.backgroundColor = [UIColor grayColor];
    [detailview addSubview:movieController.view];

    [movieController prepareToPlay];
    movieController.shouldAutoplay = NO;

    [detailview addSubview:movieController.view];

上記のコードを試してみましたが、moviecontroller がフルスクリーンの場合、縦向きモードでしか表示できません。ランドスケープモードでは表示できません。私はフルスクリーンモードのmoviecontrollerがランドスケープモードで表示できるようにしたいだけで、別のビューはポートレートモードでまだ表示されていません。私は何をすべきか?

4

4 に答える 4

4

あなたの.hファイルで

@property (strong, nonatomic) MPMoviePlayerController *moviePlayer;

.m ファイルでそのプロパティを合成します

@synthesize moviePlayer = _moviePlayer;

リソース フォルダにムービー ファイルがあるので、それに応じて名前を変更します。

            _moviePlayer =  [[MPMoviePlayerController alloc]initWithContentURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"video001" ofType:@"MOV"]]];
           [[NSNotificationCenter defaultCenter] addObserver:self
                                                     selector:@selector(moviePlayBackDidFinish:)
                                                         name:MPMoviePlayerPlaybackDidFinishNotification
                                                       object:_moviePlayer];
            _moviePlayer.controlStyle = MPMovieControlStyleDefault;
            _moviePlayer.shouldAutoplay = YES;
            [_moviePlayer prepareToPlay];
            [self.view addSubview:_moviePlayer.view];
            [_moviePlayer setFullscreen:YES animated:YES];
            [_moviePlayer stop];
            [_moviePlayer play];

フルスクリーンを閉じるには、次のようなメソッドがあります。

- (void) moviePlayBackDidFinish:(NSNotification*)notification {
    MPMoviePlayerController *player = [notification object];
    [[NSNotificationCenter defaultCenter]
     removeObserver:self
     name:MPMoviePlayerPlaybackDidFinishNotification
     object:player];

    if ([player
         respondsToSelector:@selector(setFullscreen:animated:)])
    {
        [player.view removeFromSuperview];
    }
}

それがうまくいくことを願っています。

于 2013-09-13T04:42:17.360 に答える
4

はい、2 つの通知オブザーバーを使用して完全な向きを変更できます。

まず、 AppDelegate didFinishLaunchingWithOptionsメソッドに 2 つの通知オブザーバーを追加します。

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

次に、メソッドとプロパティを追加します

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

第三に、メソッドをオーバーライドしますsupportedInterfaceOrientationsForWindow。必要な向きを返すことができます

-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
    if (self.allowRotation) {
        return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
    }
    return UIInterfaceOrientationMaskPortrait;
}
于 2014-04-11T05:13:27.863 に答える
1

ランドスケープ モードのアプリの 1 つで次のコードを使用しました。

    [moviePlayerController.view setFrame:CGRectMake(0, 0, 1024, 768)];
    [self.view addSubview:moviePlayerController.view];
    moviePlayerController.fullscreen = YES;
    moviePlayerController.repeatMode = MPMovieRepeatModeOne;
    moviePlayerController.controlStyle = MPMovieControlStyleNone;
    [moviePlayerController play];
于 2013-09-13T02:39:20.817 に答える