From 77fc4d4171927b9c32fa12bbb2c39ead8a4da35b Mon Sep 17 00:00:00 2001 From: puckey Date: Tue, 3 Oct 2023 16:49:41 +0200 Subject: [PATCH] Avoid emitting empty metadata. Using rntp, I was seeing empty values for Event.MetadataTimedReceived like: `{ "raw": [] }`. This commit filters out these empty metadata groups. --- SwiftAudioEx/Classes/Observer/AVPlayerItemObserver.swift | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/SwiftAudioEx/Classes/Observer/AVPlayerItemObserver.swift b/SwiftAudioEx/Classes/Observer/AVPlayerItemObserver.swift index 9736cf7..2ec14d9 100644 --- a/SwiftAudioEx/Classes/Observer/AVPlayerItemObserver.swift +++ b/SwiftAudioEx/Classes/Observer/AVPlayerItemObserver.swift @@ -114,6 +114,9 @@ class AVPlayerItemObserver: NSObject { extension AVPlayerItemObserver: AVPlayerItemMetadataOutputPushDelegate { func metadataOutput(_ output: AVPlayerItemMetadataOutput, didOutputTimedMetadataGroups groups: [AVTimedMetadataGroup], from track: AVPlayerItemTrack?) { - delegate?.item(didReceiveTimedMetadata: groups) + let groupsWithMetadata = groups.filter { !$0.items.isEmpty } + if !groupsWithMetadata.isEmpty { + delegate?.item(didReceiveTimedMetadata: groupsWithMetadata) + } } }