我正在为我的应用制作视频。我正在使用Avplayer。除了iPad之外,所有设备上的视频都能正常播放。第一个视频正在变得紧张。这是代码:
NSURL *url = [NSURL URLWithString:feed.video_url];
cell.videoItem = [AVPlayerItem playerItemWithURL:url];
cell.videoPlayer = [AVPlayer playerWithPlayerItem:cell.videoItem];
cell.avLayer = [AVPlayerLayer playerLayerWithPlayer:cell.videoPlayer];
[cell.avLayer setBackgroundColor:[UIColor whiteColor].CGColor];
[cell.avLayer setVideoGravity:AVLayerVideoGravityResizeAspectFill];
cell.videoPlayer.actionAtItemEnd = AVPlayerActionAtItemEndNone;
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(playerItemDidReachEnd:)
name:AVPlayerItemDidPlayToEndTimeNotification
object:[cell.videoPlayer currentItem]];
timer = [NSTimer scheduledTimerWithTimeInterval:5.0 target:self selector:@selector(hideMuteImage) userInfo:nil repeats:NO];
[cell.viewForVideo.layer addSublayer:cell.avLayer];
[cell.videoPlayer play];
请给我一些建议。谢谢
答案 0 :(得分:0)
实际上,问题是视图初始化...视图在第一次单元格执行后初始化。所以,我在填充表格单元格之前添加了,并且还将VideoGravity设置为AVLayerVideoGravityResize而不是AVLayerVideoGravityResizeAspectFill。
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
cell.viewForVideo.frame = CGRectMake(0, 0, self.view.frame.size.width - 5, 480);
}
非常感谢。