Before You Start Make Sure:
- App and Placement set up on Publisher Portal
- SDK is installed
- SDK is initialized
- Each Ad request has "Testing" status which enables it to test integrations.
Headline Video is a video only ad format that provides an option to attach the video player to the top of the feed UI as the user scrolls through their feed.
Headline Video ads are designed to be integrated into recycler views. The best practice is to extend your RecyclerView.Adapter and RecyclerView.ViewHolder (AdHolder is available in the example below), in order to pass the relevant Placement and AdRequest IDs .
Inside the adapter’s onCreateViewHolder use
HeadlineVideoAdContainer.getAdView(Context context) method to get the ad view and return it in a ViewHolder.
Inside the adapter’s onBindViewHolder you will need to retrieve HeadlineVideoAdContainer object from the Placement object by calling it’s getHeadlineVideoContainer method and passing it the ApplicationContext and the AdRequest id as parameters. Then use headlineVideoAdContainer.bindTo method to bind the Ad to the ViewHolder's itemView.
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent,
int viewType) {
context = parent.getContext().getApplicationContext();
RelativeLayout adView = HeadlineVideoAdContainer.getAdView(context);
return new AdHolder(adView);
}
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder,
int position)
{
try {
HeadlineVideoPlacement outStreamVideoPlacement =
(HeadlineVideoPlacement) Controller.getInstance()
.getPlacement(placementId);
headlineVideoPlacement.setTextColor(Color.RED);
headlineVideoPlacement.setExpandedBackgroundColor(Color.BLACK);
headlineVideoPlacement.setCollapsedBackgroundColor(Color.BLUE);
HeadlineVideoAdContainer container = headlineVideoPlacement
.getHeadlineVideoContainer(context, requestId);
container.bindTo((ViewGroup) holder.itemView);
} catch (DioSdkException e) {
// error handling
}
}
In order to customize frame and text colors use optional setters on HeadlineVideoPlacement object as showed in example.
- Call ad.close() to stop the ad and release the resources associated with it.
- Call ad.leave() to pause the video ad.
- Call ad.reenter() to resume the video ad. It is very important to notify SDK with these methods in order to get best performance and stable work.
try {
Controller.getInstance()
.getPlacement(<placementId>)
.getAdRequestById(<requestId>)
.getAdProvider().getAd().close();
} catch (DioSdkException e) {
// error handling
}
recyclerView.addOnScrollListener(new HeadlineVideoSnapListener(AD_POSITION) {
@Override
public void removeAdPositionFromList(int adPosition) {
items.remove(adPosition); // items is a dataset for your adapter
adapter.notifyDataSetChanged();
}
});
Comments
0 comments
Please sign in to leave a comment.