How to detect when AVPlayer video ends playing?

前端 未结 10 920
感动是毒
感动是毒 2020-11-28 07:48

I\'am using AVPlayer for playing local video file (mp4) in Swift. Does anyone know how to detect when video finish with playing? Thanks

10条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-28 08:18

    In Swift 3 and RxSwift 3.5 all you have to do is:

    override func viewDidLoad() {
        super.viewDidLoad()
    
        NotificationCenter.default.rx.notification(Notification.Name.AVPlayerItemDidPlayToEndTime)
            .asObservable().subscribe(onNext: { [weak self] notification in
    
                //Your action
    
            }).addDisposableTo(disposeBag)
    }
    

提交回复
热议问题