Search in sources :

Example 1 with Creative

use of org.prebid.mobile.rendering.video.vast.Creative in project prebid-mobile-android by prebid.

the class AdResponseParserVastTest method setupInLine.

private InLine setupInLine() {
    InLine mockInLine = mock(InLine.class);
    mockInLine.setCreatives(new ArrayList<>());
    Creative mockCreative = mock(Creative.class);
    when(mockCreative.getCompanionAds()).thenReturn(new ArrayList<>());
    ArrayList<Creative> creatives = new ArrayList<>();
    creatives.add(mockCreative);
    when(mockInLine.getCreatives()).thenReturn(creatives);
    return mockInLine;
}
Also used : Creative(org.prebid.mobile.rendering.video.vast.Creative) ArrayList(java.util.ArrayList) InLine(org.prebid.mobile.rendering.video.vast.InLine)

Example 2 with Creative

use of org.prebid.mobile.rendering.video.vast.Creative 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;
}
Also used : MediaFile(org.prebid.mobile.rendering.video.vast.MediaFile) Ad(org.prebid.mobile.rendering.video.vast.Ad) Creative(org.prebid.mobile.rendering.video.vast.Creative) ArrayList(java.util.ArrayList)

Aggregations

ArrayList (java.util.ArrayList)2 Creative (org.prebid.mobile.rendering.video.vast.Creative)2 Ad (org.prebid.mobile.rendering.video.vast.Ad)1 InLine (org.prebid.mobile.rendering.video.vast.InLine)1 MediaFile (org.prebid.mobile.rendering.video.vast.MediaFile)1