2017-04-19 6 views
0

상단과 하단에 검은 색 막대없이 전체 화면으로 :아래 그림과 같이 AVPlayer를 내가 내 비디오를 내장하고 notificationCenter 관찰자를 추가 한

비디오 재생이 완료
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"export" ofType:@"mp4"]; 
NSURL *videoURL = [NSURL fileURLWithPath:filePath]; 

_playerViewController = [[AVPlayerViewController alloc] init]; 
// grab a local URL to our video 
//NSURL *videoURL = [myBundle URLForResource:@"export" withExtension:@"mp4"]; 
NSLog(@"Video URL: %@",videoURL); 
if(videoURL) 
{ 

    _playerViewController.showsPlaybackControls = NO; 

    AVPlayerItem *playerItem = [AVPlayerItem playerItemWithURL:videoURL]; 

    // create an AVPlayer 
    _playerViewController.player = [AVPlayer playerWithPlayerItem:playerItem]; 
    //self.player.volume = PLAYER_VOLUME; 
    _playerViewController.modalPresentationStyle = 
    UIModalPresentationOverFullScreen; 
    AVPlayerLayer *playerLayer = [AVPlayerLayer 
    playerLayerWithPlayer:_playerViewController.player]; 
    playerLayer.videoGravity = AVLayerVideoGravityResizeAspectFill; 
    playerLayer.zPosition = -1; 
    playerLayer.frame = [UIApplication sharedApplication].keyWindow.bounds; 
    [self.playerView.layer addSublayer:playerLayer]; 

    [_playerViewController.player play]; 
    // Adding Observer for your video file, 
    NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter]; 
    [notificationCenter addObserver:self selector:@selector(videoDidFinish:) 
    name:AVPlayerItemDidPlayToEndTimeNotification object:nil]; 
} 

, 다음의 메소드가 호출 :

나는 다음보기 콘에 현재 AV보기 컨트롤러에서 밀어있어

  1. :
    -(void)videoDidFinish:(id)notification{ 
        AVPlayerItem *p = [notification object]; 
        //do something with player if you want 
        [_playerViewController.player pause]; 
    
        //Remove Observer 
        [[NSNotificationCenter defaultCenter] removeObserver:self]; 
    
         //your initial view can proceed from here 
        UIViewController *controler = [self.storyboard 
        instantiateViewControllerWithIdentifier:@"loginScreenId"]; 
        [self.navigationController pushViewController:controler animated:YES]; 
    } 
    

    나는 두 가지를 해결할 수 없어요 유모차. 성공적으로 다음보기 컨트롤러에 연결되었지만 화면의 위쪽과 아래쪽에 검은 색 막대가 있습니다. 이걸 어떻게 없앨 수 있습니까?

  2. AVPlayer를 전체 화면으로 만들려면 어떻게해야합니까?

답변

1

마지막으로 알아 냈습니다. 난 그냥 프로젝트에 Launch.storyborad을 추가하고 전체 화면 비디오를 얻을 수

playerLayer.frame = self.view.frame; 

와 코드

playerLayer.frame = [UIApplication sharedApplication].keyWindow.bounds; 

를 교체했다.

0

사용 전체 화면 용 Player.frame = self.view.bounds