AVPlayer不显示视频屏幕

时间:2016-12-06 07:57:48

标签: ios objective-c avplayer

我想用AVPlayer播放视频。问题是视频屏幕没有出现但声音来了。它只显示黑屏。

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    NSUserDefaults *prefs=[NSUserDefaults standardUserDefaults];

    //[prefs URLForKey:@"marge_video_url"];

    AVAsset *asset = [AVAsset assetWithURL:[prefs URLForKey:@"marge_video_url"]];

    AVPlayerItem *item = [AVPlayerItem playerItemWithAsset:asset];

    self.player = [AVPlayer playerWithPlayerItem:item];

    self.playerLayer = [AVPlayerLayer playerLayerWithPlayer:self.player];
    self.playerLayer.contentsGravity = AVLayerVideoGravityResizeAspect;
    self.player.actionAtItemEnd = AVPlayerActionAtItemEndNone;

    [self.VideoLayerView.layer addSublayer:self.playerLayer];

    [self.player play];

    self.videoPlaybackPosition = 0;
}

- (void)viewDidLayoutSubviews {
    self.playerLayer.frame = CGRectMake(0, 0, self.VideoView.frame.size.width, 250);
}

这个代码我用另一个控制器,可以很好地播放视频。但是这里的代码不起作用。

0 个答案:

没有答案