5

I was trying to use AVPlayerView in Swift, but the compiler complaints that it cannot find a member named player in AVPlayerView.

Error saying AVPlayerView does not have a member named "player"

But AVPlayerView clearly does have a property called player.

AVPlayerView class definition shows it has a property named "player"

And other properties or methods are fine. It seems that only player is not recognized.

Junfeng
  • 940
  • 10
  • 19

1 Answers1

7

You explicitly have to import the AVFoundation framework (which defines the AVPlayer class):

import AVKit
import AVFoundation

let playerView = AVPlayerView()
let player = playerView.player

That might be considered as a bug in the (Swift view of the) AVKit framework.

Martin R
  • 529,903
  • 94
  • 1,240
  • 1,382