diff --git a/Classes/Events/PlayerEvent.swift b/Classes/Events/PlayerEvent.swift index 3834be84..d73bd7aa 100644 --- a/Classes/Events/PlayerEvent.swift +++ b/Classes/Events/PlayerEvent.swift @@ -17,9 +17,9 @@ import AVFoundation @objc public static let allEventTypes: [PlayerEvent.Type] = [ canPlay, durationChanged, stopped, ended, loadedMetadata, play, pause, playing, seeking, seeked, replay, tracksAvailable, textTrackChanged, audioTrackChanged, videoTrackChanged, playbackInfo, stateChanged, - timedMetadata, sourceSelected, loadedTimeRanges, playheadUpdate, error, errorLog, playbackStalled, playbackRate + timedMetadata, sourceSelected, loadedTimeRanges, playheadUpdate, error, errorLog, playbackStalled, playbackRate,metadataGroups ] - + // MARK: - Player Events Static Reference /// Sent when enough data is available that the media can be played, at least for a couple of frames. @@ -58,6 +58,8 @@ import AVFoundation @objc public static let stateChanged: PlayerEvent.Type = StateChanged.self /// Sent when timed metadata is available. @objc public static let timedMetadata: PlayerEvent.Type = TimedMetadata.self + /// Sent when timed metadata Groups is available. + @objc public static let metadataGroups: PlayerEvent.Type = MetadataGroups.self /// Sent when source was selected. @objc public static let sourceSelected: PlayerEvent.Type = SourceSelected.self /// Sent when loaded time ranges was changed, loaded time ranges represent the buffered content. @@ -137,6 +139,12 @@ import AVFoundation } } + public class MetadataGroups: PlayerEvent { + convenience init(metadata: [AVDateRangeMetadataGroup]) { + self.init([EventDataKeys.metadataGroup: metadata]) + } + } + public class TracksAvailable: PlayerEvent { convenience init(tracks: PKTracks) { self.init([EventDataKeys.tracks: tracks]) diff --git a/Classes/Player/AVPlayerEngine/AVPlayerEngine+AssetLoading.swift b/Classes/Player/AVPlayerEngine/AVPlayerEngine+AssetLoading.swift index 28ed1100..df58e120 100644 --- a/Classes/Player/AVPlayerEngine/AVPlayerEngine+AssetLoading.swift +++ b/Classes/Player/AVPlayerEngine/AVPlayerEngine+AssetLoading.swift @@ -37,6 +37,10 @@ extension AVPlayerEngine { metadataOutput.setDelegate(self, queue: DispatchQueue.main) playerItem.add(metadataOutput) + let metadataCollector = AVPlayerItemMetadataCollector() + metadataCollector.setDelegate(self, queue: DispatchQueue.main) + playerItem.add(metadataCollector) + if #available(iOS 13.0, tvOS 13.0, *) { playerItem.automaticallyPreservesTimeOffsetFromLive = newAsset.playerSettings.lowLatency.automaticallyPreservesTimeOffsetFromLive @@ -136,3 +140,13 @@ extension AVPlayerEngine: AVPlayerItemMetadataOutputPushDelegate { } } } + +extension AVPlayerEngine: AVPlayerItemMetadataCollectorPushDelegate { + + public func metadataCollector(_ metadataCollector: AVPlayerItemMetadataCollector, + didCollect metadataGroups: [AVDateRangeMetadataGroup], + indexesOfNewGroups: IndexSet, + indexesOfModifiedGroups: IndexSet) { + self.post(event: PlayerEvent.MetadataGroups(metadata: metadataGroups)) + } +} diff --git a/Classes/Player/PKEvent.swift b/Classes/Player/PKEvent.swift index 5c05046a..f14413d8 100644 --- a/Classes/Player/PKEvent.swift +++ b/Classes/Player/PKEvent.swift @@ -51,6 +51,7 @@ public extension PKEvent { static let newState = "newState" static let error = "error" static let metadata = "metadata" + static let metadataGroup = "metadataGroup" static let mediaSource = "mediaSource" static let timeRanges = "timeRanges" static let bitrate = "bitrate" @@ -135,6 +136,12 @@ public extension PKEvent { return self.data?[EventDataKeys.metadata] as? [AVMetadataItem] } + /// Associated metadata group from the event, PKEvent Metadata Group Accessor + + @objc var metadataGroups: [AVDateRangeMetadataGroup]? { + return self.data?[EventDataKeys.metadataGroup] as? [AVDateRangeMetadataGroup] + } + /// The MediaSource object, PKEvent Data Accessor @objc var mediaSource: PKMediaSource? { return self.data?[EventDataKeys.mediaSource] as? PKMediaSource diff --git a/PlayKit.podspec b/PlayKit.podspec index b989865d..365e06ce 100644 --- a/PlayKit.podspec +++ b/PlayKit.podspec @@ -4,7 +4,7 @@ suffix = '.0000' # Dev mode Pod::Spec.new do |s| s.name = 'PlayKit' -s.version = '3.30.0' + suffix +s.version = '3.30.1' + suffix s.summary = 'PlayKit: Kaltura Mobile Player SDK - iOS' s.homepage = 'https://github.com/kaltura/playkit-ios' s.license = { :type => 'AGPLv3', :text => 'AGPLv3' }