use of org.prebid.mobile.rendering.video.vast.MediaFile 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;
}