You can implement your own opportunity detectors by implementing the interface PlacementOpportunityDetector.
new AdvertisingFactory() {
....
@Override
public PlacementOpportunityDetector createOpportunityDetector(MediaPlayerItem item) {
return new CustomPlacementOpportunityDetector();
}
....
}
// register the custom advertising factory with media player advertisingFactory = createCustomAdvertisingFactory(); mediaPlayer.registerAdClientFactory(advertisingFactory);
public List<PlacementOpportunity> process(List<TimedMetadata> timedMetadataList, Metadata metadata)
The timedMetadataList contains the list of available TimedMetadata, which is sorted. Metadata contains the targeting parameters and the custom parameters to be sent to the ad provider.
PlacementOpportunity(
String id, // can be id from timedMetadata
PlacementInformation placementInformation // PlacementInformation object containing Type, time, duration
Metadata metadata // ad metadata containing targeting params sent to the ad provider
)
This is a sample custom placement opportunity detector:
public class CustomPlacementOpportunityDetector implements PlacementOpportunityDetector {
...
@Override
public List<PlacementOpportunity> process(List<TimedMetadata> timedMetadataList, Metadata metadata) {
...
List<PlacementOpportunity> opportunities = new ArrayList<PlacementOpportunity>();
for (TimedMetadata timedMetadata : timedMetadataList) {
if (isOpportunity(timedMetadata)) { // check if given timedMetadata should be considered as an opportunity
// create an object of PlacementOpportunity and add it to the opportunities list
PlacementOpportunity opportunity = createPlacementOpportunity(timedMetadata, airingId, metadata);
Opportunities.add(opportunity);
}
}
return opportunities;
}
...
}