NSString *urlPath;
NSURL *videoUrl;
urlPath = [[NSBundle mainBundle] pathForResource:@"fogLoop" ofType:@"mp4"];
videoUrl = [NSURL fileURLWithPath:urlPath];
avPlayer = [AVPlayer playerWithURL:videoUrl];
avPlayerLayer = [AVPlayerLayer playerLayerWithPlayer:avPlayer];
avPlayerLayer.frame = videoView.layer.bounds;
avPlayerLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
[videoView.layer addSublayer: avPlayerLayer];
avPlayer.actionAtItemEnd = AVPlayerActionAtItemEndNone;
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(playerItemDidReachEnd:)
name:AVPlayerItemDidPlayToEndTimeNotification
object:[avPlayer currentItem]];
[avPlayer play];
我在这个视图上有几个 UILabel。我真的只是想把视频作为背景元素。使用此代码,它似乎可以播放所有 UI 元素。如何让它进入后台?