swift - terminating with uncaught exception of type NSException error -


i have simple app 2 mp4 playing on loop. mp4 ends, app crashes , error:

"terminating uncaught exception of type nsexception"

here's code. error mean , how can fix it?

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      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)     }   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()         }     } } 
 2016-02-06 19:33:41.874 lietava 2[1214:107001] -[lietava_2.display loopvideo]: unrecognized selector sent instance 0x79a44b60 2016-02-06 19:33:41.879 lietava 2[1214:107001] *** terminating app due uncaught exception 'nsinvalidargumentexception', reason: '-[lietava_2.display loopvideo]: unrecognized selector sent instance 0x79a44b60' *** first throw call stack: (     0   corefoundation                      0x00582a14 __exceptionpreprocess + 180     1   libobjc.a.dylib                     0x02735e02 objc_exception_throw + 50     2   corefoundation                      0x0058bd63 -[nsobject(nsobject) doesnotrecognizeselector:] + 275     3   corefoundation                      0x004c96bd ___forwarding___ + 1037     4   corefoundation                      0x004c928e _cf_forwarding_prep_0 + 14     5   foundation                          0x00adaa76 __57-[nsnotificationcenter addobserver:selector:name:object:]_block_invoke_2 + 40     6   corefoundation                      0x0054a5f4 __cfnotificationcenter_is_calling_out_to_an_observer__ + 20     7   corefoundation                      0x0054a2aa _cfxregistrationpost + 458     8   corefoundation                      0x00549ff6 ___cfxnotificationpost_block_invoke + 54     9   corefoundation                      0x005963d3 -[_cfxnotificationregistrar find:object:observer:enumerator:] + 1795     10  corefoundation                      0x00430667 _cfxnotificationpost + 599     11  foundation                          0x00a14b87 -[nsnotificationcenter postnotification:] + 131     12  avfoundation                        0x001dec85 __avplayeritem_fpitemnotificationcallback_block_invoke + 6034     13  libdispatch.dylib                   0x03178377 _dispatch_call_block_and_release + 15     14  libdispatch.dylib                   0x0319b9cd _dispatch_client_callout + 14     15  libdispatch.dylib                   0x03180f90 _dispatch_main_queue_callback_4cf + 910     16  corefoundation                      0x004d3fde __cfrunloop_is_servicing_the_main_dispatch_queue__ + 14     17  corefoundation                      0x00491cd4 __cfrunlooprun + 2356     18  corefoundation                      0x004910e6 cfrunlooprunspecific + 470     19  corefoundation                      0x00490efb cfrunloopruninmode + 123     20  graphicsservices                    0x04ce4664 gseventrunmodal + 192     21  graphicsservices                    0x04ce44a1 gseventrun + 104     22  uikit                               0x01265bfa uiapplicationmain + 160     23  lietava 2                           0x0009ef0c main + 140     24  libdyld.dylib                       0x031c5a21 start + 1 ) libc++abi.dylib: terminating uncaught exception of type nsexception (lldb)  

by exception wrote, change code:

 nsnotificationcenter.defaultcenter().addobserver(self,         selector: "loopvideo:", //added : <---         name: avplayeritemdidplaytoendtimenotification,         object:nil) 

the selector : indicates function should receive argument.
in case, notification center searched method loopvideo doesn't take args


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 -