使用定時元資料

當當前播放時間與開始時間匹配時,可以使用TimedMetadata。

使用這些保存的 PTTimedMetadata 在回放期間使用保存的字典 在調度時儲存定時元資料對象

  1. 提取並更新此通知中的當前播放時間,並查找 PTTimedMetadata 對象的起始時間與當前回放時間匹配。

    可以使用這些對象完成各種操作。

    例如:

    - (void) onMediaPlayerTimeChange:(NSNotification *)notification
    {
        CMTimeRange seekableRange = self.player.seekableRange;
        if (CMTIMERANGE_IS_VALID(seekableRange))
        {
            int currentTime = (int) CMTimeGetSeconds(self.player.currentTime);
            NSArray *allKeys = timedMetadataCollection ? [timedMetadataCollection allKeys] : [NSArray array];
            NSMutableArray *timedMetadatasToDelete = [[[NSMutableArray alloc] init] autorelease];
            int count = [allKeys count];
    
            for (int i=count - 1; i > -1; i--)
            {
               NSNumber *currTimedMetadataTime = allKeys[i];
               if ([currTimedMetadataTime integerValue] == currentTime)
               {
                /*
                    Use the timed metadata here and remove it from the collection.
                */
                 NSLog (@"IN PLAYBACK TIME %i TO EXECUTE TIMEDMETADATA %@ scheduled at time %f",currentTime,currTimedMetadata.name,CMTimeGetSeconds(currTimedMetadata.time));
    
                PTTimedMetadata *currTimedMetadata = [timedMetadataCollection objectForKey:currTimedMetadataTime];
                [timedMetadatasToDelete addObject:currTimedMetadataTime];
               }
            }
    
            for (int i=0; i<[timedMetadatasToDelete count]; i++)
            {
                NSNumber *timedMetadataToDelete = timedMetadatasToDelete[i];
                [timedMetadataCollection removeObjectForKey:timedMetadataToDelete];
            }
        }
    }
    
  2. 定期刷新陳舊 PTTimedMetadata 從清單中實例,以防止記憶體持續增長。

本頁內容