iOS 13 - сбой avPlayer.currentTime (). Секундная проверка - PullRequest
0 голосов
/ 03 марта 2020

Столкнулся с cra sh в тиковом методе, так как я вижу долго работающий l oop, запущенный из setuptimer, я буферирую аудио из веб-сервиса и применяю воспроизведение / пауза и продолжение.

func setupTimer(){
            NotificationCenter.default.addObserver(self, selector: #selector(self.didPlayToEnd), name: .AVPlayerItemDidPlayToEndTime, object: nil)
            timer = Timer(timeInterval: 0.001, target: self, selector: #selector(myclass.tick), userInfo: nil, repeats: true)
            RunLoop.current.add(timer!, forMode: RunLoopMode.commonModes)
        }


@objc func tick(){
        if((avPlayer.currentTime().seconds == 0.0) && (isPaused == false)){ //crasing in this line because of loop
            seekLoadingLabel.alpha = 1
        }else{
            seekLoadingLabel.alpha = 0
        }

        if(isPaused == false){
            if(avPlayer.rate == 0){
                avPlayer.play()
                //seekLoadingLabel.alpha = 1
            }else{
                //seekLoadingLabel.alpha = 0
            }
        }

Cra sh отчет

Crashed: com.apple.main-thread
0  Myapp                   0x1001e5b84 MyDetailTableViewCell.tick() + 283 (CPObjectDetailTableViewCell.swift:283)  
1  Myapp                   0x1001e5bdc @objc MyTableViewCell.tick() + 4337966044 (<compiler-generated>:4337966044)  
2  Foundation              0x1a729c028 __NSFireTimer + 64  
3  CoreFoundation          0x1a6e3103c __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 28  
4  CoreFoundation          0x1a6e30d78 __CFRunLoopDoTimer + 880  
5  CoreFoundation          0x1a6e30448 __CFRunLoopDoTimers + 276  
6  CoreFoundation          0x1a6e2b584 __CFRunLoopRun + 1920  
7  CoreFoundation          0x1a6e2aadc CFRunLoopRunSpecific + 464  
8  GraphicsServices        0x1b0dcb328 GSEventRunModal + 104  
9  UIKitCore               0x1aaf3863c UIApplicationMain + 1936  
10 MyApp                   0x1001a7a60 main + 25 (AppDelegate.swift:25)  
11 libdyld.dylib           0x1a6cb4360 start + 4  

1 Ответ

0 голосов
/ 05 марта 2020

Я решил эту проблему, проверив объект avPlayer на наличие нулевого значения, используя необязательную цепочку.

if let avPlayerObj = avPlayer {
            print("Contains a value! It is \(avPlayerObj)! execute tick()")

}else {
            print("Doesn’t contain a avPlayerObj or nil")
        }
...