Set up for customized playback

You can customize or override ad behaviors supported by PSDK in two ways. In either case, you must register the ad policy instance with the PSDK.

To customize ad behaviors, your application can either:

  • Implement the AdPolicySelector interface and implement all its methods.

    This is recommended if you need to override all the default ad behaviors.

  • Extend the DefaultAdPolicySelector class and provide implementations for only those behaviors that require customization.

    This is recommended if you need to override only some of the default behaviors.

In both cases, do the following.

  1. Assign the policy instance to be used by the PSDK through the advertising factory.
    Note: Any custom ad policy that is registered at the beginning of playback is cleared when the MediaPlayer instance is deallocated. Your application must register a policy selector instance every time a new playback session is created.
    For example:
    // create a Custom Advertising Factory
        private AdvertisingFactory createCustomAdvertisingFactory() {
            return new AdvertisingFactory() {
                ...
                @Override
                public AdPolicySelector createAdPolicySelector(MediaPlayerItem mediaPlayerItem) {
                    return new CustomAdPolicySelector(mediaPlayerItem);
                }
                ...
            };
        }
    // register the custom advertising factory with media player
    advertisingFactory = createCustomAdvertisingFactory();
    mediaPlayer.registerAdClientFactory(advertisingFactory);
  2. Implement any customizations.