2016-08-05 18 views
0

我使用AVPlayer播放視頻。我在全屏模式下遇到問題。視頻播放器來自左上角。它看起來很奇怪。AVPlayerview來自左上角

NSString *filePath = [self.video_Array objectAtIndex:index]; 
NSString *soundFilePath = [[NSBundle mainBundle] pathForResource:filePath ofType: nil]; 
url = [[NSURL alloc] initFileURLWithPath: soundFilePath]; 
currentItem = [AVPlayerItem playerItemWithURL:url]; 
_playerViewController = [[AVPlayerViewController alloc] init]; 
_playerViewController.videoGravity = AVLayerVideoGravityResize; 
_playerViewController.view.frame = self.view.bounds; 
_playerViewController.showsPlaybackControls = NO; 
_video=[AVPlayer playerWithURL:url]; 
_video = [AVPlayer playerWithPlayerItem:currentItem]; 
_playerViewController.player = _video; 
[_playerViewController.player play]; 
[self.view addSubview:_playerViewController.view]; 
+1

顯示屏幕截圖或相關代碼總是 –

+0

檢查上面的代碼 – Bharathi

+0

嘗試調整視頻引力 – Shubhank

回答

0

您可以使用AVPlayerViewController播放全屏視頻

AVPlayerViewController+Fullscreen.h 

#import <AVKit/AVKit.h> 

@interface AVPlayerViewController (Fullscreen) 

-(void)goFullscreen; 

@end 

AVPlayerViewController + Fullscreen.m

#import "AVPlayerViewController+Fullscreen.h" 

@implementation AVPlayerViewController (Fullscreen) 



-(void)goFullscreen { 
     self.modalPresentationStyle = UIModalPresentationOverFullScreen; 
     [self presentViewController:self animated:YES completion:nil]; 
    } 

@end 
1

請參考我的代碼,這是工作在我的應用精細,

-(void)videoPlayer:(NSString *)filePath{ 

    playerViewController = [[AVPlayerViewController alloc] init]; 
    self.viewPlayerContainer.frame = CGRectMake(0, 74, self.view.bounds.size.width, self.view.bounds.size.width); 

    NSURL *url = [NSURL fileURLWithPath:filePath]; 

    AVURLAsset *asset = [AVURLAsset assetWithURL: url]; 
    AVPlayerItem *item = [AVPlayerItem playerItemWithAsset: asset]; 

    AVPlayer * player = [[AVPlayer alloc] initWithPlayerItem: item]; 
    playerViewController.player = player; 
    playerViewController.videoGravity = AVLayerVideoGravityResizeAspectFill; 
    [playerViewController.view setFrame:CGRectMake(0, 0, self.viewPlayerContainer.bounds.size.width, self.viewPlayerContainer.bounds.size.height)]; 
    [playerViewController addObserver:self forKeyPath:@"videoBounds" options:NSKeyValueObservingOptionNew context:nil]; 

    playerViewController.showsPlaybackControls = YES; 

    [self.viewPlayerContainer addSubview:playerViewController.view]; 

    [player play]; 
}