我看到一個類似的問題,我正在問如何將AVPlayerLayer添加到NS視圖,但我看不到有完整的源代碼來了解它是如何工作的。我的問題的核心是我創建一個球員對象,並通過移動NSURL來初始化它。我創建一個AVPlayerLayer對象並用播放器初始化它。當我嘗試將AVPlayerLayer添加到自己(我是NSView)並運行該程序時,我什麼都沒有收到。開始圖形...添加AVPlayerLayer到NSView
NSURL *movie = [[NSURL alloc] initWithString:@"file://localhost/Users/matthewmichal/Desktop/A%20Good%20To%20Die%20Hard.mov"];
[player initWithURL:movie];
[self setWantsLayer:YES];
AVPlayerLayer *playerLayer = [AVPlayerLayer playerLayerWithPlayer:player];
[self.layer addSublayer:playerLayer];
[player play];