Implementar un generador de oportunidades personalizado

Puede implementar sus propios generadores de oportunidades implementando la clase OportunityGenerator .

  1. Implemente su ContentFactory personalizado implementando la interfaz ContentFactory y anulando retrieveGenerators.

    Por ejemplo:

    class MyContentFactory extends ContentFactory {
        @Override
        public List<OpportunityGenerator> retrieveGenerators(MediaPlayerItem item) {
            List<OpportunityGenerator> generators = new ArrayList<OpportunityGenerator>();
            generators.add(MyOpportunityGenerator(item));
            return generators;
        }
        ...
    }
    
  2. Registre el ContentFactory en el MediaPlayer.

    Por ejemplo:

    // register the custom content factory with media player
    MediaPlayerItemConfig config =  new MediaPlayerItemConfig();
    config.setAdvertisingFactory(new MyContentFactory());
    
    // this config will should be later passed while loading the resource
    mediaPlayer.replaceCurrentResource(resource, config);
    
    // OR use MediaPlayerItemLoader to pre-load a resource
    id = 23;
    itemLoader.load(resource, id, config);
    
  3. Cree una clase de generador de oportunidades personalizada que implemente la clase OpportunityGenerator.

    public class CustomOpportunityGenerator implements OpportunityGenerator
    {...}
    
    1. En el generador de oportunidades personalizado, anule doConfigure, doUpdate y doCleanup:

      @Override
       public void configure(MediaPlayerItem item, Context context,
       OpportunityGeneratorClient client, AdSignalingMode mode, long playhead, TimeRange playbackRange) {
      }
      
      protected void update(long playhead, TimeRange playbackRange){
      }
      
      protected void cleanup(){
      }
      

      Para obtener los metadatos temporizados:

      List<TimedMetadata> tList = getItem().getTimedMetadata();
      
    2. Para cada TimedMetadata o grupo de TimedMetadata, cree una oportunidad con los siguientes atributos:

      Opportunity(
        String id,                      // Can be id from timedMetadata
        Placement placementInformation, // Placement object containing Type, time, duration
        Metadata metadataSettings,      // Ad metadata with targeting params sent to the ad provider
        Metadata customParams           // Metadata for customizing resolving and/or tracking process.
      );
      
    3. Para cada oportunidad creada, llame a resolve en el OpportunityGeneratorClient:getClient().resolve(opportunity);.

Este es un detector de oportunidades de colocación personalizado de ejemplo:

public class MyOpportunityGenerator implements OpportunityGenerator {

     @Override
      public void configure(MediaPlayerItem item, Context context,
      OpportunityGeneratorClient client, AdSignalingMode mode, long playhead, TimeRange playbackRange) {
      }

        MediaPlayerItem item = getItem();
        MediaPlayerItemConfig itemConfig = item.getConfig();

        if (itemConfig == null || itemConfig.getAdvertisingMetadata() == null) {
            // no ad metadata, no ads
            return;
        }

        AdvertisingMetadata metadata = item.getConfig().getAdvertisingMetadata();

        AdSignalingMode mode = itemConfig.getAdSignalingMode();

        if (mode == AdSignalingMode.CUSTOM_RANGES)
        {
            // don't override custom ad ranges
            return;
        }

        Placement.Type pType = (mode == AdSignalingMode.MANIFEST_CUES) ?
                  Placement.Type.PRE_ROLL : Placement.Type.SERVER_MAP;
        Placement.Mode pMode = Placement.Mode.DEFAULT;
        Placement placement = new Placement(pType, playhead,
                  Placement.UNKNOWN_DURATION, pMode);

        Opportunity opportunity = new Opportunity("initialOpportunity", placement,
                  metadata, null);

        OpportunityGeneratorClient client = getClient();
        client.resolve(opportunity);
    }

    @Override
    protected void update(long playhead, TimeRange playbackRange) {

 ...
 timedMetadataList = getItem().getTimedMetadata();
        for (TimedMetadata timedMetadata : timedMetadataList) {
         if (isOpportunity(timedMetadata)) {   // check if given timedMetadata should
                                               // be considered as an opportunity
  // create a PlacementOpportunity object and add it to the opportunities list
                Opportunity opportunity = new Opportunity("id", placement, metadata, null);
                client.resolve(opportunity)
          }
        }
    }

    @Override
    protected void cleanup() {}
}

En esta página