백그라운드에서 비디오를 재생하려고합니다. 많은 튜토리얼을 따라 왔지만 적절한 결과를 얻지 못했습니다. AVPlayer를 사용하고 있습니다.이 URL을 통해 응용 프로그램 상태가 재생 될 때마다 내 비디오를 재생할 수 있습니다. 하지만 배경에서 avPlayerLayer를 분리해야합니다. 배경에서 avPlayerLayer에 액세스하려고 할 때마다 NULL이 반환됩니다. 도와주세요. AVPlayer에서 AVPlayerLayer를 분리하는 방법은 무엇입니까?
이
내 코드입니다 :이 늦은 답변입니다- (void)viewDidLoad
{
[super viewDidLoad];
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
[self becomeFirstResponder];
[[AVAudioSession sharedInstance] setDelegate: self];
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
[[AVAudioSession sharedInstance] setActive: YES error: nil];
NSURL *url = [[NSBundle mainBundle] URLForResource:@"sample"
withExtension:@"m4v"
subdirectory:nil];
avPlayerItem = [AVPlayerItem playerItemWithURL:url];
self.songPlayer = [AVPlayer playerWithPlayerItem:avPlayerItem];
self.avPlayerLayer = [AVPlayerLayer playerLayerWithPlayer: self.songPlayer];
self.avPlayerLayer.frame = self.view.layer.bounds;
UIView *newView = [[UIView alloc] initWithFrame:self.view.bounds];
[newView.layer addSublayer:avPlayerLayer];
[self.view addSubview:newView];
[ self.songPlayer play];
// Do any additional setup after loading the view, typically from a nib.
}
iewController *vc=[[ViewController alloc]init];
NSLog(@"%@",vc.avPlayerLayer);
vc.avPlayerLayer = [AVPlayerLayer playerLayerWithPlayer:nil];
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{
ViewController *vc=[[ViewController alloc]init];
vc.avPlayerLayer = [AVPlayerLayer playerLayerWithPlayer:vc.songPlayer];
}