Set up metadata for ad insertion

Use the helper class AuditudeSettings, which extends the MetadataNode class, to set up Ad Decisioning metadata.

  1. Build the AuditudeSettings instance.
    AuditudeSettings auditudeSettings = new AuditudeSettings();
    
  2. Set the Ad Decisioning mediaID, zoneID, domain, and, optionally, targeting parameters.
    auditudeSettings.setZoneId("yourZoneId");
    auditudeSettings.setMediaId("yourVideoId");
    auditudeSettings.setDefaultMediaId("defVideoId");
    auditudeSettings.setDomain("yourAuditudeDomain");
    Metadata targetingParameters = new MetadataNode();
    targetingParameters.setValue("desired_param", "desired_value");
    auditudeSettings.setTargetingParameters(targetingParameters);
    MetadataNode result = new MetadataNode();
    result.setNode(DefaultMetadataKeys.AUDITUDE_METADATA_KEY.getValue(), auditudeSettings);
    
  3. Create a MediaResource instance using the media stream URL and the previously created advertising metadata.
    MediaResource mediaResource = MediaResource.createFromUrl("http://example.com/media/test_media.m3u8", MetadataNode); 
    
  4. Load the MediaResource object through the MediaPlayer.replaceCurrentItem method.

    The MediaPlayer starts loading and processing the media stream manifest.

  5. When the MediaPlayer transitions to the INITIALIZED status, get the media stream characteristics in the form of a MediaPlayerItem instance through the MediaPlayer.getCurretItem method.
  6. Query the MediaPlayerItem instance to see whether the stream is live, whether it has alternate audio tracks, or whether it is protected.
  7. Call MediaPlayer.prepareToPlay to start the advertising workflow.

    After the ads have been resolved and placed on the timeline, the MediaPlayer transitions to the PREPARED state.

  8. Call MediaPlayer.play to start the playback.
The PSDK now includes ads when your media plays.