Skip to content

Commit

Permalink
Add metadata group menifest event (#480)
Browse files Browse the repository at this point in the history
* Add metadata group observer and event

* update pod version to 3.30.1
  • Loading branch information
imberezin authored May 29, 2024
1 parent 5212edd commit 402eaaa
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
12 changes: 10 additions & 2 deletions Classes/Events/PlayerEvent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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])
Expand Down
14 changes: 14 additions & 0 deletions Classes/Player/AVPlayerEngine/AVPlayerEngine+AssetLoading.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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))
}
}
7 changes: 7 additions & 0 deletions Classes/Player/PKEvent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion PlayKit.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -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' }
Expand Down

0 comments on commit 402eaaa

Please sign in to comment.