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

iOS 13.3 downloader porcessActions递归调用到Stack内存crash #73

Open
wentaozone opened this issue Mar 11, 2020 · 1 comment
Open

Comments

@wentaozone
Copy link

wentaozone commented Mar 11, 2020

环境:Xcode 11.3.1 iPhone XR 13.3

在cell中切换播放视频: 切换视频方式为 销毁avplayer,销毁avplayerLayer,再重新创建.
原因: https://www.cnblogs.com/sundaysgarden/articles/9080511.html

主要代码:
`
private func prepareToPlay(_ item:AVPlayerItem? = nil){

    if let item = item {
        self.player = AVPlayer(playerItem: item)
    }else{
        self.player = AVPlayer()
    }
    playerLayer = AVPlayerLayer(player: self.player)
    playerLayer?.frame = self.bounds
    self.playerView.layer.insertSublayer(playerLayer!, at: 0)
    self.player!.actionAtItemEnd = .none
    
    self.player!.addObserver(self, forKeyPath: "status", options: .new, context: nil)
    NotificationCenter.default.addObserver(self, selector: #selector(didPlayToEndTime(_:)), name: Foundation.Notification.Name.AVPlayerItemDidPlayToEndTime, object: nil)
    self.timeObServer = self.player!.addPeriodicTimeObserver(forInterval: CMTime(value: 1, timescale: 30), queue: .main) {[unowned self] (time) in
        
        self.currentTime = time
        
        guard let currentItem = self.player?.currentItem else {return}
        let curretnTime = Float(self.currentTime.value) / Float(self.currentTime.timescale)
        let totalTime = Float(CMTimeGetSeconds(currentItem.duration))
        let progress = (curretnTime/totalTime)/self.progressSlider.maximumValue
        if !self.progressSlider.isTracking{
            self.progressSlider.setValue(progress, animated: true)
        }

        if totalTime > 0{
            let date = Date(timeIntervalSince1970: TimeInterval(curretnTime))
            let format = curretnTime > 3600 ? "hh:mm:ss" : "mm:ss"
            let xxx = date.toString(format: format, timezone:TimeZone(abbreviation: "UTC")!)
            let date1 = Date(timeIntervalSince1970: TimeInterval(totalTime))
            let format1 = totalTime > 3600 ? "hh:mm:ss" : "mm:ss"
            let xxx1 = date1.toString(format: format1, timezone:TimeZone(abbreviation: "UTC")!)
            
            self.timeLabel.text = "\(xxx) / \(xxx1)"
        }
    }
}
private func stop(){
    if let indexPath =  self.userInfo as? IndexPath{
        print("视频操作: 停止 \(indexPath) \(String(describing: url))")
    }
    self.playState = .Init
    guard let player = self.player else {return}
    if player.timeControlStatus != .paused{
        player.removeObserver(self, forKeyPath: "status")
        player.removeTimeObserver(self.timeObServer as Any)
        player.pause()
        resourceManager.cancelLoaders()
        NotificationCenter.default.removeObserver(self, name: Foundation.Notification.Name.AVPlayerItemDidPlayToEndTime, object: nil)
    }
    if player.currentItem != nil{
        player.replaceCurrentItem(with: nil)
    }
    self.player = nil
    if let avlayer = self.playerLayer {
        avlayer.removeFromSuperlayer()
        self.playerLayer = nil
    }
    
    
    self.playBtn.isSelected = false
    self.playBtn.setImage(UIImage(named: "vp_button_play"), for: .normal)
    self.coverImageView.isHidden = false
    self.show()
}

`

image

原因在于获取cacheActions数量太多导致process递归调用层次太深。猜想这里可以把多个连续块合并为一个块,而大大减小生成的cacheActions数量。 或者直接限制一个Request获取的 actions数量不要超过1000.

image

@panmingyang2009
Copy link

panmingyang2009 commented Sep 20, 2022

可能在这个 PR 里被修复了:#85

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

2 participants