crash – choque para @escaping @callee_guaranteed (@unowned CMTime), agregar el código (guard let self = self else{return}) en el bloque, pero no funciona.
Mis usuarios están enfrentando este error que se reportó dentro de Firebase Crashlytics. Puedo ver la Clase y el Método donde tuvo lugar el error, pero no pude encontrar la razón del fallo. Todo funciona bien dentro del simulador y en el dispositivo real que tengo.
Agregué ese código pero no funciona. Necesito ayuda para determinar la causa real de este error. Aquí está el registro del fallo.
Comenzó a fallar: com.apple.main-thread
0 FPMeditation 0x16c234 clausura #1 en PlayerManager.addPlayObserver () + 4376789556 (AudioPlayer.swift:4376789556)
1 FPMeditation 0x166f74 destreza para @escaping @callee_guaranteed (@unowned CMTime) -> () + 4376768372 (<compiler-generated>:4376768372)
2 AVFCore 0xc46c - [AVPeriodicTimebaseObserver _fireBlockForTime:] + 68
3 AVFCore 0xc3ac - [AVPeriodicTimebaseObserver _handleTimeDiscontinuity] + 168
4 AVFCore 0xbf2c__AVTimebaseObserver_timebaseNotificationCallback_block_invoke + 116
5 libdispatch.dylib 0x2914 _dispatch_call_block_and_release + 32
6 libdispatch.dylib 0x4660 _dispatch_client_callout + 20
7 libdispatch.dylib 0x12b60 _dispatch_main_queue_callback_4CF + 944
8 CoreFoundation 0x51cd4 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 16
9 CoreFoundation 0xbeac __CFRunLoopRun + 2540
10 CoreFoundation 0x1f3b8 CFRunLoopRunSpecific + 600
11 GraphicsServices 0x138c GSEventRunModal + 164
12 UIKitCore 0x5196a8 - [UIApplication _run] + 1100
13 UIKitCore 0x2987f4 UIApplicationMain + 2092
14 libswiftUIKit.dylib 0x31184 UIApplicationMain (_: _: _: :) + 104
15 FPMeditation 0x3491cprincipal + 4375513372 (ReminderTableViewCell.swift:4375513372)
16 ??? 0x103281a24 (desaparecido)
Y el código real.
func addPlayObserver() {
// Playback status monitoring
avPlayer.currentItem?.addObserver(self, forKeyPath: "status", options: NSKeyValueObservingOptions.new, context: nil)
//Buffering status monitoring
avPlayer.currentItem?.addObserver(self, forKeyPath: "loadedTimeRanges", options: NSKeyValueObservingOptions.new, context: nil)
avPlayer.addObserver(self, forKeyPath: "loadedTimeRanges", options: NSKeyValueObservingOptions.new, context: nil)
AVAudioSession.sharedInstance().addObserver(self, forKeyPath: "isOtherAudioPlaying", options: NSKeyValueObservingOptions.new, context: nil)
// Playing end event monitoring
NotificationCenter.default.addObserver(self, selector: #selector(onItemDidPlayToEndTime), name: NSNotification.Name.AVPlayerItemDidPlayToEndTime, object: self.avPlayer.currentItem)
// Playing failure monitoring
NotificationCenter.default.addObserver(self, selector: #selector(onItemFailedToPlayToEndTime), name: NSNotification.Name.AVPlayerItemFailedToPlayToEndTime, object: self.avPlayer.currentItem)
NotificationCenter.default.addObserver(self, selector: #selector(onItemPlaybackStalled), name: NSNotification.Name.AVPlayerItemPlaybackStalled, object: self.avPlayer.currentItem)
// Monitor normal interruption events such as calls and alarms
NotificationCenter.default.addObserver(self, selector: #selector(interruptionNotification), name: AVAudioSession.interruptionNotification, object: nil)
// Is it starting to play?
var isStartPlay = false
// Set the timer to monitor and update the playback progress
timeObserver = avPlayer.addPeriodicTimeObserver(forInterval: CMTime.init(value: 1, timescale: 1), queue: DispatchQueue.main, using: {[weak self] (time) in
guard let self = self else{return}
// Loading is complete and play begins.
// The reason for the pre-judgment condition "self?.playStatus! = .prepare":
// Sometimes, maybe you played first, and the ready event came back later. For example:
// 1. Play and call seekto at the same time
// 2. Local music also is
if isStartPlay == false, time.value > 0, self.playStatus != .prepare {
isStartPlay = true
self.playStatus = .play
}
// Only begin to play
if time.value > 0{
// calculates the playback progress
self.playProgress = self.calculatePlayProgress()
}
// Playback progress
if (self.playStatus == .play) {// State filtering to avoid the 'ready' event that has not returned and the duration is 0.
let progress = time.seconds / CMTimeGetSeconds((self.avPlayer.currentItem!.duration))
self.currentProgress = progress
// Whether to perform statistics when progress reaches 20%
if progress == 0.2 && self.isStatisticWhenTwenteen == true {
self.isStatisticWhenTwenteen = false
self.handleStatisticPlayProgress()
}
// Set the actual playback time
PlayerFinishManager.shared.setupRealPlayRealTotalTime(seconds: Int(self.avPlayer.currentItem!.duration.seconds))
}
})
}
davy.ai
Solución de problemas de un informe de error de Firebase Crashlytics
Como experto en TI especializado en iOS, Swift y AVPlayer, ha recibido un informe de error de Firebase Crashlytics. El informe indica que los usuarios experimentan un error en una Clase y Método específicos, pero no puede identificar la causa del error. La aplicación funciona bien en su simulador y dispositivo personal.
Al revisar el registro de errores, nota que el error ocurre en el hilo principal y que la declaración
guard
dentro de la funciónaddPlayObserver()
no funciona correctamente. Sin embargo, es poco probable que esta declaraciónguard
sea la causa raíz del error.Para diagnosticar aún más el problema, debe revisar el código en busca de posibles problemas. En este caso, parece que la función
addPlayObserver()
es responsable de registrar varios observadores y notificaciones relacionados con AVPlayer. Dependiendo del dispositivo y las condiciones de red del usuario, es posible que uno de estos observadores o notificaciones desencadene una condición de carrera, lo que lleva al error.Para solucionar este problema, puede considerar los siguientes pasos:
Depurar el código: revise la función
addPlayObserver()
e intente identificar posibles problemas. Verifique cualquier suposición sobre el estado de la aplicación o la red que no siempre son verdaderos.Probar en diferentes dispositivos: pruebe la aplicación en diferentes dispositivos y condiciones de red para ver si el error es universal o específico de ciertos dispositivos o condiciones.
Revisar otros informes de error: revise otros informes de error en Firebase Crashlytics para ver si hay patrones o problemas similares que puedan estar relacionados con este problema.
Siguiendo estos pasos, podrá aislar y abordar el problema que causa el error en su aplicación.