您可以實作介面PlacementOpportunityDetector,來實作您自己的機會檢測器。
建立自訂AdvertisingFactory
例項並覆寫createOpportunityDetector
。 例如:
new AdvertisingFactory() {
...
@Override
public PlacementOpportunityDetector createOpportunityDetector(MediaPlayerItem item) {
return new CustomPlacementOpportunityDetector();
}
...
}
向MediaPlayer
註冊廣告客戶端工廠。 例如:
// register the custom advertising factory with media player
advertisingFactory = createCustomAdvertisingFactory();
mediaPlayer.registerAdClientFactory(advertisingFactory);
建立可擴展PlacementOpportunityDetector
類的自定義機會檢測器類。
在自訂機會檢測器中,覆寫此函式:
public List<PlacementOpportunity> process(List<TimedMetadata> timedMetadataList, Metadata metadata)
timedMetadataList
包含可用TimedMetadata
的清單,該清單已排序。 中繼資料包含要傳送給廣告提供者的定位參數和自訂參數。
對於每個TimedMetadata
,建立List<PlacementOpportunity>
。 清單可以是空的,但不能是空的。 PlacementOpportunity
應具有下列屬性:
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
)
為所有檢測到的定時元資料對象建立放置機會後,只需返回PlacementOpportunity
清單。
這是自訂位置機會檢測器範例:
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;
}
...
}