xcode - Why is if statement in this function never true -
i have function in swift uiview makes 2 mp4`s loop. first mp4 playing fine second 1 not, seems play once, how fix this?
let videourl: nsurl = nsbundle.mainbundle().urlforresource(instrumentaimp4[skaicius], withextension: "mp4")! let sakeleurl: nsurl = nsbundle.mainbundle().urlforresource("sakele_blikas", withextension: "mp4")! player = avplayer(url: videourl) player?.actionatitemend = .none player?.muted = true sakele = avplayer(url: sakeleurl) sakele?.actionatitemend = .none sakele?.muted = true let playerlayer = avplayerlayer(player: player) playerlayer.videogravity = avlayervideogravityresizeaspectfill playerlayer.zposition = 1 let playerlayer2 = avplayerlayer(player: sakele) playerlayer2.videogravity = avlayervideogravityresizeaspectfill playerlayer2.zposition = 1 view.layer.addsublayer(playerlayer2) view.layer.addsublayer(playerlayer) player?.play() sakele?.play() //loop video nsnotificationcenter.defaultcenter().addobserver(self, selector: "loopvideo:", name: avplayeritemdidplaytoendtimenotification, object:nil) func loopvideo(notification: nsnotification) { if let finishedplayer = notification.object as! avplayeritem!{ if finishedplayer == self.sakele { self.sakele?.seektotime(kcmtimezero) self.sakele?.play() nslog("1") }else{ self.player?.seektotime(kcmtimezero) self.player?.play() nslog("2")} }}
nslog ("2") never happens. mistake? apreciated
your sakele
avplayer. notification.object
claimed (and cast to) avplayeritem, assigned finishedplayer
. makes no sense. when come compare if finishedplayer == self.sakele
, can never succeed, because not same kind of object, let alone same object.
Comments
Post a Comment