in Education by
I'm adapting my app to Swift 3 and I'm encountering this problem. This used to work on Swift 2.2 but now it's broken. moviePlayBackFinished never gets called. I tried adding the observer in multiple ways, all without success. NotificationCenter.default.addObserver(self, selector: #selector(self.moviePlayBackFinished(_:)), name: NSNotification.Name.AVPlayerItemDidPlayToEndTime, object: player.currentItem); NotificationCenter.default.addObserver(self, selector: #selector(moviePlayBackFinished(_:)), name: NSNotification.Name.AVPlayerItemDidPlayToEndTime, object: player.currentItem); NotificationCenter.default.addObserver(self, selector: #selector(self.moviePlayBackFinished(sender:)), name: NSNotification.Name.AVPlayerItemDidPlayToEndTime, object: player.currentItem); // (...) @objc func moviePlayBackFinished(sender : AnyObject) { print("playbackFinished"); let zeroCM : CMTime = CMTime(seconds: 0, preferredTimescale: 1000000000); playerLayer.player?.seek(to: zeroCM); } @objc func moviePlayBackFinished(_ notification: Notification) { print("playbackFinished"); let zeroCM : CMTime = CMTime(seconds: 0, preferredTimescale: 1000000000); playerLayer.player?.seek(to: zeroCM); } Any ideas would be appriciated. Thank you JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
There are multiple possible reason of this issue. NotificationCenter .default .addObserver(self, selector: #selector(self.moviePlayBackFinished(sender:)), name: .AVPlayerItemDidPlayToEndTime, object: player.currentItem) First of all, you have to set object to nil. AVPlayerItemDidPlayToEndTime notification automatically set object to the AVPlayerItem which reached at the end. If you change it manually, you will not get any notification of AVPlayerItemDidPlayToEndTime. Second, according to the AVPlayerItemDidPlayToEndTime documentation: Important This notification may be posted on a different thread than the one on which the observer was registered. So, to make sure you should check the notification is on the thread you want. It doens't matter you added observer from UIViewController or AVPlayer subclass.

Related questions

0 votes
    I am using Realm with Swift 3 in my iOS app. I have the following code //Find all records for the day func ... { let predicate = NSPredicate(format: "date >= %@ and date...
asked May 8, 2022 in Education by JackTerrance
0 votes
    I would like to specify an additional default shortcut class to a set of classes, similarly to that @each ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 20, 2022 in Education by JackTerrance
0 votes
    How can I get the value of the amp selector and save it in a php variable 1 1 1 I tried ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 6, 2022 in Education by JackTerrance
0 votes
    I'm new to UiPath and I'm following all the tutorials available in their website, Planning also to finish the ... ? Thanks in advance. Select the correct answer from above options...
asked Feb 8, 2022 in Education by JackTerrance
0 votes
    SA=1000.00 AI=0.12 MP=100.00 def remainb(x): if x==0: return 0 else: return x=(SA+(AI/12)*SA)-MP for ... . run the loop until SA==0). Select the correct answer from above options...
asked Jan 11, 2022 in Education by JackTerrance
0 votes
    Write whether the following statements are true or false, with the suitable reason: i. Pollen tube reaches the ... personal hygiene. Select the correct answer from above options...
asked Nov 9, 2021 in Education by JackTerrance
0 votes
0 votes
0 votes
    I have a view with a text field in it, but the text field is at the bottom. When I click the keyboard, it pops up ... to push the rest of the view up when a keyboard comes up?...
asked Mar 9, 2021 by JackTerrance
0 votes
    I have the following cronjobs in my crontab: 0 22 * * 1-6 /root/sbin/mysqlbackup --conf-dir=/ ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 3, 2022 in Education by JackTerrance
0 votes
    In my case, savepoint was set in Java and I am trying to rollback in a plsql procedure which was ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 1, 2022 in Education by JackTerrance
0 votes
    I've inherited a codebase that implements a half-baked implementation of custom intents and shortcuts. One ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 21, 2022 in Education by JackTerrance
0 votes
    As it currently stands, this question is not a good fit for our Q&A format. We expect answers to ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 27, 2022 in Education by JackTerrance
0 votes
    8. YOU CAN NEVER STORE 2 FILES OF THE SAME NAME IN THE SAME________ Select the correct answer from above options...
asked Dec 9, 2021 in Education by JackTerrance
0 votes
    8. YOU CAN NEVER STORE 2 FILES OF THE SAME NAME IN THE SAME________ Select the correct answer from above options...
asked Dec 3, 2021 in Education by JackTerrance
...