Marcar rangos

Para implementar los PTTimeRangeCollection y marcar los rangos de contenido como anuncios:

  1. Prepare el PTTimeRangeCollection.

  2. Establezca el tipo de PTTimeRangeCollection en PTTimeRangeCollectionTypeMarkRanges.

    Este paso notifica a TVSDK que los intervalos personalizados deben tratarse como anuncios.

    #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. Cree el PTAdMetadata y establezca el 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. Cree el reproductor e inicie la reproducción.

    //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];
    

Reemplazar rangos

Para implementar los PTTimeRangeCollection y eliminar intervalos de contenido como anuncios:

  1. Preparar PTTimeRangeCollection.

  2. Establezca el tipo de PTTimeRangeCollection en PTTimeRangeCollectionTypeReplaceRanges.

    Este paso notifica a TVSDK que los intervalos proporcionados deben reemplazarse por contenido alternativo (anuncios).

    #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];
    
    SUGERENCIA

    El argumento replacementDuration es opcional. Si no se define, el AdServer determina la duración de la pausa publicitaria.

  3. Cree el PTAdMetadata y establezca el 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];
    
    SUGERENCIA

    Aunque el signalingMode se establece como PTAdSignalingModeCustomRanges, este modo de señalización de publicidad se configura automáticamente al configurar el PTTimeRangeCollection de tipo PTTimeRangeCollectionTypeReplace.

  4. Cree el reproductor e inicie la reproducción.

    //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];
    

Eliminar intervalos

Para implementar los PTTimeRangeCollection y eliminar intervalos de contenido como anuncios:

  1. Prepare el PTTimeRangeCollection.

  2. Establezca el tipo de PTTimeRangeCollection en PTTimeRangeCollectionTypeDeleteRanges, que notifica a TVSDK que es necesario eliminar los intervalos proporcionados.

    #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. Cree el PTAdMetadata y establezca el 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];
    
    SUGERENCIA

    La inserción de publicidad se produce después de eliminar los intervalos personalizados basados en PTAdMetadata y en el PTAdSignalingMode actual.

  4. Cree el reproductor e inicie la reproducción.

    //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];
    

En esta página