MMPlayerView icon indicating copy to clipboard operation
MMPlayerView copied to clipboard

exception can remove observer

Open fukemy opened this issue 4 years ago • 1 comments

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 avatar Apr 03 '21 07:04 fukemy

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

fukemy avatar Apr 03 '21 08:04 fukemy