Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

exception can remove observer #116

Open
fukemy opened this issue Apr 3, 2021 · 1 comment
Open

exception can remove observer #116

fukemy opened this issue Apr 3, 2021 · 1 comment

Comments

@fukemy
Copy link

fukemy commented Apr 3, 2021

i got this error, please help:

Ảnh chụp Màn hình 2021-04-03 lúc 14 09 09
code:

@objc fileprivate func startLoading() {
        self.updateByContentOffset()
        if self.presentedViewController != nil {
            return
        }
        print("play : \(mmPlayerLayer.playUrl)")
        // start loading video
        mmPlayerLayer.resume()
    }
    
    fileprivate func updateByContentOffset() {
        if let path = findFirstMediaCellVisible(), self.presentedViewController == nil {
            self.updateCell(at: path)
        }
    }
    
    private func findFirstMediaCellVisible() -> IndexPath? {
        let visible = messagesCollectionView.indexPathsForVisibleItems
        guard visible.count > 0 else { return nil }
        
        return visible.first(where: { messagesCollectionView.cellForItem(at: $0) is MediaMessageCell} )
    }
    
    func updateCell(at indexPath: IndexPath) {
        print("updateCell: \(NSStringFromClass(messagesCollectionView.cellForItem(at: indexPath)!.classForCoder))")
        let message = messageList[indexPath.section]
        guard case let .video(videoItem) = message.kind else { return }
        if let cell = messagesCollectionView.cellForItem(at: indexPath) as? MediaMessageCell {
            // this thumb use when transition start and your video dosent start
//            mmPlayerLayer.thumbImageView.image = cell.im
            // set video where to play
            print("set mm for index: \(indexPath) - \(message.sender.displayName)")
            mmPlayerLayer.playView = cell.imageView
            mmPlayerLayer.set(url: videoItem.url)
        }
    }
override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        
        
        offsetObservation = messagesCollectionView.observe(\.contentOffset, options: [.new]) { [weak self] (_, value) in
            guard let self = self, self.presentedViewController == nil else {return}
            NSObject.cancelPreviousPerformRequests(withTarget: self)
            self.perform(#selector(self.startLoading), with: nil, afterDelay: 0.2)
        }
    }
    
    override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)
        NotificationCenter.default.removeObserver(self)
        mmPlayerLayer.player?.pause()
    }
@fukemy
Copy link
Author

fukemy commented Apr 3, 2021

im solved when using 6.0.2 version, but it's support only IOS 12, while my app need provide ios 11, can u help me know why lasted version only support ios 12? Thanks in advance

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant