xcode - Both videos keep reseting when 1 ends -


i have 2 mp4 videos playing on screen, , both of them supposed loop. both reset @ same time, when 1 ends. how adjust code videos loop separately?

    let videourl: nsurl = nsbundle.mainbundle().urlforresource("duda", withextension: "mp4")!     let sakeleurl: nsurl = nsbundle.mainbundle().urlforresource("sakele_blikas", withextension: "mp4")!       player = avplayer(url: videourl)     player?.actionatitemend = .none     player?.muted = true      player2 = avplayer(url: sakeleurl)     player2?.actionatitemend = .none     player2?.muted = true      let playerlayer = avplayerlayer(player: player)     playerlayer.videogravity = avlayervideogravityresizeaspectfill     playerlayer.zposition = -1      let playerlayer2 = avplayerlayer(player: player2)     playerlayer2.videogravity = avlayervideogravityresizeaspectfill     playerlayer2.zposition = -1        playerlayer.frame = cgrect(x: 50.0, y: 100.0, width: 240.0, height: 433.0)     playerlayer2.frame = cgrect(x:647.0, y: 90.0, width: 115.0, height: 44.0)      view.layer.addsublayer(playerlayer)     view.layer.addsublayer(playerlayer2)     player?.play()     player2?.play()      //loop video     nsnotificationcenter.defaultcenter().addobserver(self,         selector: "loopvideo",         name: avplayeritemdidplaytoendtimenotification,         object:nil)      nsnotificationcenter.defaultcenter().addobserver(self, selector: "loopvideo2", name: avplayeritemdidplaytoendtimenotification, object: nil)    } 

func loopvideo(notification: nsnotification) {

if let finishedplayer = notification.object as! avplayer! {     if finishedplayer == self.player2     {       self.player2?.seektotime(kcmtimezero)       self.player2?.play()     } else {       self.player?.seektotime(kcmtimezero)       self.player?.play()     } } 

}

heres error code not sure how format it

2016-02-08 16:44:15.222 lietava 2[1928:361895] -[lietava_2.display loopvideo]: unrecognized selector sent instance 0x14679cb0 

2016-02-08 16:44:15.224 lietava 2[1928:361895] * terminating app due uncaught exception 'nsinvalidargumentexception', reason: '-[lietava_2.display loopvideo]: unrecognized selector sent instance 0x14679cb0' * first throw call stack: (0x2138810b 0x20b2ee17 0x2138d925 0x2138b559 0x212bbc08 0x2133ce9d 0x2133c8a7 0x2133c685 0x213902db 0x2129ea53 0x2685604b 0x12b6c97 0x12b6c83 0x12bb76d 0x2134b3fd 0x213498f7 0x2129cbf9 0x2129c9e5 0x224e8ac9 0x2552cba1 0x114ea0 0x20f4b873) libc++abi.dylib: terminating uncaught exception of type nsexception

so have these 2 lines of code:

//loop video nsnotificationcenter.defaultcenter().addobserver(self,     selector: "loopvideo",     name: avplayeritemdidplaytoendtimenotification,     object:nil)  nsnotificationcenter.defaultcenter().addobserver(self,      selector: "loopvideo2",      name: avplayeritemdidplaytoendtimenotification,      object: nil) 

which registering 2 functions called exact same notification. you're not determining there video (or video player) has finished up.

but have way this.

the object passed along in avplayeritemdidplaytoendtimenotification notification "is item finished playing".

try doing:

func loopvideo(notification: nsnotification) {      if let finishedplayer = notification.object avplayer!     {         if finishedplayer == self.player2         {           self.player2?.seektotime(kcmtimezero)           self.player2?.play()         } else {           self.player1?.seektotime(kcmtimezero)           self.player1?.play()         }     } } 

for work, need make player1 , player2 properties of view controller (instead of local variables live in viewdidload or viewwillappear functions).


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -