使用案例刪除和替換廣告

以下是刪除和替換廣告的使用案例:

標籤範圍

實施 PTTimeRangeCollection 將內容範圍標籤為廣告:

  1. 準備 PTTimeRangeCollection

  2. 設定 PTTimeRangeCollectionPTTimeRangeCollectionTypeMarkRanges

    此步驟通知TVSDK必須將自定義範圍視為廣告。

    #define PSDK_TIMESCALE 100000
    
    NSArray *ranges =  @[
      [PTReplacementRange
        replacementRangeWithRange:CMTimeRangeMake(CMTimeMakeWithSeconds
          (0, PSDK_TIMESCALE),CMTimeMakeWithSeconds(60, AD_TIMESCALE))],
      [PTReplacementRange
        replacementRangeWithRange:CMTimeRangeMake(CMTimeMakeWithSeconds
          (120, PSDK_TIMESCALE),CMTimeMakeWithSeconds(60, AD_TIMESCALE))]
    ];
    
    PTTimeRangeCollection *timeRangeCollection =
      [[PTTimeRangeCollection alloc] initWithRanges:ranges
        type:PTTimeRangeCollectionTypeMarkRanges];
    
  3. 建立 PTAdMetadata 並設定 PTTimeRangeCollection

    // Create the PTPlayerItem metadata
    PTMetadata *metadata = [[PTMetadata alloc] init];
    
    // Create the Ad metadata
    PTAuditudeMetadata *adMetadata = [[PTAuditudeMetadata alloc] init];
    adMetadata.timeRangeCollection = timerangeCollection;
    
    //Set Ad metadata
    [metadata setMetadata:adMetadata forKey:PTAdResolvingMetadataKey];
    
    //Create PTMediaPlayerItem
    PTMediaPlayerItem *playerItem = [[[PTMediaPlayerItem alloc] initWithUrl:mediaUrl
                                                                    mediaId:mediaId
                                                                   metadata:metadata];
    
  4. 建立播放器並開始播放。

    //Create PTMediaPlayer using the created PTMediaPlayer
    PTMediaPlayer *player = [PTMediaPlayer playerWithMediaPlayerItem:playerItem];
    
    //Add player to the player UIView
    [self.playerView addSubview:(UIView *)player.view];
    
    //Start playback
    [player play];
    

替換範圍

實施 PTTimeRangeCollection 將內容範圍作為廣告刪除:

  1. 準備 PTTimeRangeCollection

  2. 設定 PTTimeRangeCollectionPTTimeRangeCollectionTypeReplaceRanges

    此步驟通知TVSDK需要用備用內容(廣告)替換提供的範圍。

    #define PSDK_TIMESCALE 100000
    
    NSArray *ranges =  @[
      [PTReplacementRange replacementRangeWithRange:CMTimeRangeMake(CMTimeMakeWithSeconds
        (0, PSDK_TIMESCALE),CMTimeMakeWithSeconds(60, AD_TIMESCALE))
        replacementDuration:CMTimeMakeWithSeconds(30, AD_TIMESCALE)],
      [PTReplacementRange replacementRangeWithRange:CMTimeRangeMake(CMTimeMakeWithSeconds
        (120, PSDK_TIMESCALE),CMTimeMakeWithSeconds(60, AD_TIMESCALE))
        replacementDuration:CMTimeMakeWithSeconds(30, AD_TIMESCALE)]
                        ];
    
    PTTimeRangeCollection *timeRangeCollection =
      [[PTTimeRangeCollection alloc] initWithRanges:ranges
                                               type:PTTimeRangeCollectionTypeReplaceRanges];
    
    秘訣

    論點 replacementDuration 為可選項。 如果未定義, AdServer 確定廣告分段的持續時間。

  3. 建立 PTAdMetadata 並設定 PTTimeRangeCollection

    //Create the PTPlayerItem metadata
    PTMetadata *metadata = [[PTMetadata alloc] init];
    
    //Create the Ad metadata
    PTAuditudeMetadata *adMetadata = [[PTAuditudeMetadata alloc] init];
    adMetadata.timeRangeCollection = timerangeCollection;
    adMetadata.zoneId = adZoneId;
    adMetadata.domain = adDomain;
    adMetadata.signalingMode = PTAdSignalingModeCustomRanges;
    
    //Set Ad metadata
    [metadata setMetadata:adMetadata forKey:PTAdResolvingMetadataKey];
    
    //Create PTMediaPlayerItem
    PTMediaPlayerItem *playerItem = [[[PTMediaPlayerItem alloc] initWithUrl:mediaUrl
                                                                    mediaId:mediaId
                                                                   metadata:metadata];
    
    秘訣

    儘管 signalingMode 設定為 PTAdSignalingModeCustomRanges,此ad信令模式在設定 PTTimeRangeCollection 類型 PTTimeRangeCollectionTypeReplace

  4. 建立播放器並開始播放。

    //Create PTMediaPlayer using the created PTMediaPlayer
    PTMediaPlayer *player = [PTMediaPlayer playerWithMediaPlayerItem:playerItem];
    
    //Add player to the player UIView
    [self.playerView addSubview:(UIView *)player.view];
    
    //Start playback
    [player play];
    

刪除範圍

實施 PTTimeRangeCollection 將內容範圍作為廣告刪除:

  1. 準備 PTTimeRangeCollection

  2. 設定 PTTimeRangeCollectionPTTimeRangeCollectionTypeDeleteRanges,它通知TVSDK需要刪除提供的範圍。

    #define PSDK_TIMESCALE 100000
    
    NSArray *ranges =  @[
      [PTReplacementRange replacementRangeWithRange:CMTimeRangeMake(CMTimeMakeWithSeconds
        (0, PSDK_TIMESCALE),CMTimeMakeWithSeconds(60, AD_TIMESCALE))],
      [PTReplacementRange replacementRangeWithRange:CMTimeRangeMake(CMTimeMakeWithSeconds
        (120, PSDK_TIMESCALE),CMTimeMakeWithSeconds(60, AD_TIMESCALE))]
    ];
    
    PTTimeRangeCollection *timeRangeCollection =
      [[PTTimeRangeCollection alloc] initWithRanges:ranges
                                               type:PTTimeRangeCollectionTypeDeleteRanges];
    
  3. 建立 PTAdMetadata 並設定 PTTimeRangeCollection

    //Create the PTPlayerItem metadata
    PTMetadata *metadata = [[PTMetadata alloc] init];
    
    //Create the Ad metadata
    PTAuditudeMetadata *adMetadata = [[PTAuditudeMetadata alloc] init];
    adMetadata.timeRangeCollection = timerangeCollection;
    adMetadata.zoneId = adZoneId;
    adMetadata.domain = adDomain;
    adMetadata.signalingMode = PTAdSignalingModeServerMap;
    
    //Set Ad metadata
    [metadata setMetadata:adMetadata forKey:PTAdResolvingMetadataKey];
    
    //Create PTMediaPlayerItem
    PTMediaPlayerItem *playerItem = [[[PTMediaPlayerItem alloc] initWithUrl:mediaUrl
                                                                    mediaId:mediaId
                                                                   metadata:metadata];
    
    秘訣

    廣告插入在根據 PTAdMetadata 和當前 PTAdSignalingMode

  4. 建立播放器並開始播放。

    //Create PTMediaPlayer using the created PTMediaPlayer
    PTMediaPlayer *player = [PTMediaPlayer playerWithMediaPlayerItem:playerItem];
    
    //Add player to the player UIView
    [self.playerView addSubview:(UIView *)player.view];
    
    //Start playback
    [player play];
    

本頁內容