解決
このコードを使用すると、再生タイプを簡単に検出できます。
NotificationCenter.default.addObserver(
forName: NSNotification.Name.AVPlayerItemNewAccessLogEntry,
object: nil,
queue: OperationQueue.main) { [weak self] (notification) in
guard let self = self else { return }
guard let playerItem = notification.object as? AVPlayerItem,
let lastEvent = playerItem.accessLog()?.events.last else {
return
}
// Here you can set the type (LIVE | VOD | FILE or unknow if it's a nil):
print("Playback Type: \(lastEvent.playbackType ?? "NA")")
}
オブザーバーコードを、通常それらを聞き始める場所に追加します。
また、deinitでオブザーバーを削除することを忘れないでください;)
deinit {
NotificationCenter.default.removeObserver(self,
name: NSNotification.Name.AVPlayerItemNewAccessLogEntry,
object: self)
}
これが誰かを助けることを願っています:)