2

我正在使用 AVPLayer 在 UITableView 中播放视频。视频播放正常,但最初播放视频时,有声音出现,但屏幕为黑色。视频播放 5-6 秒后可见。我正在使用以下代码:

 AVURLAsset *asset = [AVURLAsset URLAssetWithURL:url options:nil];
playerItem = [AVPlayerItem playerItemWithAsset:asset];
AVPlayer *avPlayer = [AVPlayer playerWithPlayerItem:playerItem];
self.avPlayer = avPlayer;

__weak CLBAVPlayer *weakSelf = self;
[self.avPlayer addPeriodicTimeObserverForInterval:CMTimeMakeWithSeconds(1.0 / 60.0, NSEC_PER_SEC)
                                            queue:nil
                                       usingBlock:^(CMTime time) {
                                           [weakSelf progress];
                                       }];

self.layer = [AVPlayerLayer playerLayerWithPlayer:self.avPlayer];
self.avPlayer.actionAtItemEnd = AVPlayerActionAtItemEndNone;

请帮我找出问题所在。

4

1 回答 1

3

我得到了这个答案。实际上问题是,当我获取层并将其添加为子层时,它不在主队列中。与主队列一起使用dispatch_async解决了我的问题。

于 2016-04-25T12:10:51.430 回答