当前位置 : 主页 > 手机开发 > ios >

ios – 退出全屏后MPMoviePlayerController缩放模式问题

来源:互联网 收集:自由互联 发布时间:2021-06-11
我只是通过使用MPMoviePlayerController播放视频…我的代码是 -(void)playMovie:(NSURL *)url{ moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url]; if (IDIOM==IPAD) { [moviePlayer.view setFrame:CGRectMake(22,10
我只是通过使用MPMoviePlayerController播放视频…我的代码是

-(void)playMovie:(NSURL *)url
{
    moviePlayer =
    [[MPMoviePlayerController alloc]
     initWithContentURL:url];
    if (IDIOM==IPAD) {
        [moviePlayer.view setFrame:CGRectMake(22,100, 720, 300)];
    }
    else
    {
        (IS_IPHONE_5)? [moviePlayer.view setFrame:CGRectMake(22, 70, 280, 150)]:[moviePlayer.view setFrame:CGRectMake(22, 40, 260, 140)];
    }
    [_scrollView addSubview:moviePlayer.view];
    moviePlayer.scalingMode =MPMovieScalingModeFill;
    [moviePlayer prepareToPlay];
    [moviePlayer play];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerDidEnterFullscreen:) name:MPMoviePlayerDidEnterFullscreenNotification object:Nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerDidExitFullScreen:) name:MPMoviePlayerDidExitFullscreenNotification object:Nil];

}

-(void)moviePlayerDidEnterFullscreen :(id)sender
{
    NSLog(@"fullscreen");
   [moviePlayer play];
    moviePlayer.scalingMode =MPMovieScalingModeFill;

}

- (void) moviePlayerDidExitFullScreen:(id)sender {

    NSLog(@"exit full screen");
    [moviePlayer play];
    moviePlayer.scalingMode =MPMovieScalingModeFill;

}

这里当我最初播放视频时将处于“MPMovieScalingModeFill”模式…但我的问题是如果我按全屏它会在全屏显示视频..当我按退出“全屏”然后我的视频模式转到“MPMovieScalingModeAspectFit “mode.but我需要始终处于”MPMovieScalingModeFill“模式.我的代码出错了.请帮帮我……

我相信这会生成MPMoviePlayerScalingModeDidChangeNotification.

[[NSNotificationCenter defaultCenter] addObserver:self 
                selector:@selector(movieScalingModeDidChange:) 
                name:MPMoviePlayerScalingModeDidChangeNotification 
                object:nil];

资料来源:Apple Doc

MPMoviePlayerScalingModeDidChangeNotification

在电影播放器​​的缩放模式发生变化时发布.没有userInfo字典.缩放模式可以通过编程或用户交互进行更改.要设置或检索影片播放器的缩放模式,请访问其scalingMode属性.状态已更改的电影播放器​​可用作与通知关联的对象.

网友评论