use of org.prebid.mobile.rendering.video.vast.Ad in project prebid-mobile-android by prebid.
the class AdResponseParserVast method getAdVerification.
public AdVerifications getAdVerification(AdResponseParserVast parserVast, int index) {
Ad ad = parserVast.mVast.getAds().get(index);
if (ad == null || ad.getInline() == null) {
return null;
}
// The Inline object itself can have an adVerifications node
if (ad.getInline().getAdVerifications() != null) {
return ad.getInline().getAdVerifications();
}
// Walk Extensions and look for adVerifications nodes
if (ad.getInline().getExtensions() == null) {
return null;
}
ArrayList<Extension> extensions = ad.getInline().getExtensions().getExtensions();
if (extensions != null) {
for (Extension extension : extensions) {
if (extension.getAdVerifications() != null) {
return extension.getAdVerifications();
}
}
}
return null;
}
use of org.prebid.mobile.rendering.video.vast.Ad in project prebid-mobile-android by prebid.
the class AdResponseParserVast method getMediaFileUrl.
// Returns the best media file fit for the device
public String getMediaFileUrl(AdResponseParserVast parserVast, int index) {
String myBestMediaFileURL = null;
ArrayList<MediaFile> eligibleMediaFiles = new ArrayList<>();
/**
* Here we use a recursion pattern to traverse the nested VAST nodes "parserVast",
* until we reach the last nested node, which should be InLine,
* and then we get its meduaFile URL. Note that index is hardcoded in the call
* as 0 for the first Ad node. So we have to figure out a solution for Ad pods.
*/
if (mWrappedVASTXml != null) {
mWrappedVASTXml.getMediaFileUrl(mWrappedVASTXml, index);
} else /**
* Now that we have reached the last node, we can get its mediaFileUrl.
* Note that index is hardcoded in the call
* as 0 for the first Ad node. So we have to figure out a solution for Ad pods.
*/
{
Ad ad = parserVast.mVast.getAds().get(index);
for (Creative creative : ad.getInline().getCreatives()) {
if (creative.getLinear() != null) {
for (MediaFile mediaFile : creative.getLinear().getMediaFiles()) {
if (supportedVideoFormat(mediaFile.getType())) {
eligibleMediaFiles.add(mediaFile);
}
}
if (eligibleMediaFiles.size() == 0) {
return myBestMediaFileURL;
}
// choose the one with the highest resolution amongst all
MediaFile best = eligibleMediaFiles.get(0);
int bestValues = (Utils.isBlank(best.getWidth()) ? 0 : Integer.parseInt(best.getWidth())) * (Utils.isBlank(best.getHeight()) ? 0 : Integer.parseInt(best.getHeight()));
myBestMediaFileURL = best.getValue();
for (int i = 0; i < eligibleMediaFiles.size(); i++) {
MediaFile current = eligibleMediaFiles.get(i);
int currentValues = (Utils.isBlank(current.getWidth()) ? 0 : Integer.parseInt(current.getWidth())) * (Utils.isBlank(current.getHeight()) ? 0 : Integer.parseInt(current.getHeight()));
if (currentValues > bestValues) {
bestValues = currentValues;
best = current;
myBestMediaFileURL = best.getValue();
}
}
}
}
}
return myBestMediaFileURL;
}