Casos de uso para eliminar y reemplazar anuncios

Estos son los casos de uso para eliminar y reemplazar anuncios:

Marcar intervalos

Para implementar la variable PTTimeRangeCollection y marcar intervalos de contenido como anuncios:

  1. Prepare el PTTimeRangeCollection.

  2. Defina el tipo de PTTimeRangeCollection hasta PTTimeRangeCollectionTypeMarkRanges.

    Este paso notifica a TVSDK de 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 configure 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 intervalos

Para implementar la variable PTTimeRangeCollection y elimine intervalos de contenido como anuncios:

  1. Preparar PTTimeRangeCollection.

  2. Defina el tipo de PTTimeRangeCollection hasta PTTimeRangeCollectionTypeReplaceRanges.

    Este paso notifica a TVSDK de 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 está definida, la variable AdServer determina la duración de la pausa publicitaria.

  3. Cree el PTAdMetadata y configure 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 la variable signalingMode se ha establecido como PTAdSignalingModeCustomRanges, este modo de señalización de publicidad se configura automáticamente al configurar la variable 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 la variable PTTimeRangeCollection y elimine intervalos de contenido como anuncios:

  1. Prepare el PTTimeRangeCollection.

  2. Defina el tipo de PTTimeRangeCollection hasta PTTimeRangeCollectionTypeDeleteRanges, que notifica a TVSDK de 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 configure 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 anuncios se produce después de eliminar los intervalos personalizados basados en el PTAdMetadata y el actual PTAdSignalingMode.

  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