ios - [AVPlayerLayer superview]: unrecognized selector sent to instance in Swift -
in storyboard put view inside of uiviewcontroller. added necessary parameters there:
and connected code:
in code have:
import avkit import avfoundation @iboutlet weak var yawpvideo: avplayerlayer! override func viewdidload() { let url:nsurl = nsurl(string: videourl)! player = avplayer(url: url) yawpvideo.player = player player.play() }
and causes error:
*** terminating app due uncaught exception 'nsinvalidargumentexception', reason: '-[avplayerlayer superview]: unrecognized selector sent instance 0x7fe320cb2030'
can tell me causes problem , how can fixed?
a uiview
not calayer
, cannot add avplayerlayer
storyboard.
instead, after view has loaded, programmatically add avplayer's playerlayer
uiview's layer.
change outlet uiview
:
@iboutlet weak var yawpvideo: uiview!
then, add layer:
player = avplayer(url: url) let playerlayer = avplayerlayer(player: player) yawpvideo.layer.addsublayer(playerlayer)
Comments
Post a Comment