Store timed-metadata objects as they are dispatched

Your application is responsible for using the appropriate PTTimedMetadata objects at the appropriate times.

During content parsing, which happens prior to playback, the PSDK identifies subscribed tags and notifies your application about them. Therefore, the time associated with each PTTimedMetadata is the absolute time on the playback timeline.

NOTE: The code below assumes that there is only a single PTTimedMetadata instance at a given time. If there are multiple instances, the application must save them appropriately into a dictionary (one method is to create an array at a given time and store all instances in that array).

Your application must:
  1. Keep track of the current playback time.
  2. Match the current playback time against the already-dispatched PTTimedMetadata objects.
  3. Use the PTTimedMetadata where the start time equals the current playback time. The following example shows how to save PTTimedMetadata objects in a NSMutableDictionary (timedMetadataCollection) keyed by the start time of each timedMetadata.
    NSMutableDictionary *timedMetadataCollection;
     
    - (void)onMediaPlayerSubscribedTagIdentified:(NSNotification *)notification
    {
        if (!timedMetadataCollection)
        {
            timedMetadataCollection = [[NSMutableDictionary alloc] init];
        }
        NSDictionary *userInfo = [notification userInfo];
        PTTimedMetadata *timedMetadata = [(PTTimedMetadata *)[userInfo objectForKey:PTTimedMetadataKey] retain];
        if ([timedMetadata.name  isEqualToString: @"#EXT-OATCLS-SCTE35"])
        {
             NSLog(@"Adding timedMetadata %@ to timedMetadataCollection with time                     
                     %f",timedMetadata.name,CMTimeGetSeconds(timedMetadata.time));
     
            NSNumber *timedMetadataStartTime = [NSNumber numberWithInt:(int)CMTimeGetSeconds(timedMetadata.time)];
            [timedMetadataCollection setObject:timedMetadata forKey:timedMetadataStartTime];
        }
        [timedMetadata release];
    }