I'am using AVPlayer for playing local video file (mp4) in Swift. Does anyone know how to detect when video finish with playing? Thanks
相关问题
- CALayer - backgroundColor flipped?
- Core Data lightweight migration crashes after App
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- State preservation and restoration strategies with
相关文章
- 现在使用swift开发ios应用好还是swift?
- UITableView dragging distance with UIRefreshContro
- Could I create “Call” button in HTML 5 IPhone appl
- Using if let syntax in switch statement
- TCC __TCCAccessRequest_block_invoke
- Where does a host app handle NSExtensionContext#co
- Unable to process app at this time due to a genera
- Enum with associated value conforming to CaseItera
Swift 3.0
To get the
AVPlayerItemDidPlayToEndTimeNotification
your object needs to be anAVPlayerItem
.To do so, just use the
.currentItem
property on yourAVPlayer
Now you will get a notification once the video ends!
See my example:
Swift 3
Don't forget to remove the Observer in your
deinit
Swift 4.0
This one works for me. Thanks to @Channel
Swift 3.0
I know there are a lot of accepted answers here...
But, another route might be to add a boundary time observer to your AVPlayer. You would have to have the duration of the video, which you can get from your
player.currentItem
, and then add it as your desired time boundary.In Swift 3 and RxSwift 3.5 all you have to do is: