Playing a video ad

Triggering the Video Download

To ensure that the Service is triggered into downloading videos for your customers, enter the following into your AndroidManifest.xml file:

<service android:name="com.fyber.cache.CacheVideoDownloadService" android:exported="false/>

Playing the Video

After requesting offers, if one of your ad networks has a video available, the onAdAvailable(rewardedVideoIntent) method of your listener is called. In this case, you can start playing the video at any time simply by starting the received intent:

// let's assume 1234 as the request code which can be then used in the onActivityResult callback on your activity
startActivityForResult(rewardedVideoIntent, 1234);

Warning: To avoid multiple calls of startActivityForResult() method, it is encouraged to check if the rewardedVideo Intent is null before calling it and assinging null to intent after invoking it.

if(rewardedVideoIntent != null){
	startActivityForResult(rewardedVideoIntent, 1234);
	rewardedVideoIntent = null; 
}

For this example we’re assuming that you’re calling the method above from one of your app’s Activity.

At this point you’ve passed control of the UX flow to the SDK, which will notify your at the end of the engagement with the Activity return value:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
	// let's assume that the requestCode for a video engagement is 1234 (as specified above)
	if (resultCode == RESULT_OK && requestCode == 1234) {
		String engagementResult = data.getStringExtra(RewardedVideoActivity.ENGAGEMENT_STATUS);
	}
}

Configuring the Rewarded Video Controller

To be able to show the close button of the video player after a certain delay, you would add a new meta-data entry to the AndroidManifest.xml file with the key SPVideoPlayerOptionCloseButtonDelay (SDKs < 8.0.0) or FybVideoPlayerOptionCloseButtonDelay.

The value type should be an Integer (e.g. 5 - The close button will only show up after 5 seconds):

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
    [..]
    <application>
        [...]
        <meta-data
            android:name="FYBVideoPlayerOptionCloseButtonDelay"
            android:value="5" />
    </application>
</manifest>

Checking Engagement Results

To check the engagement results you would import the following:

	import com.fyber.ads.videos.RewardedVideoActivity;

The result of the engagement is the value returned by the activity and can have one of the following values:

RewardedVideoActivity Description
REQUEST_STATUS_PARAMETER_FINISHED_VALUE The video has finished after completing. The user will be rewarded.
REQUEST_STATUS_PARAMETER_ABORTED_VALUE The video has finished before completing. The user might have aborted it, either explicitly (by tapping the close button) or implicitly (by switching to another app) or it was interrupted by an asynchronous event like an incoming phone call.
REQUEST_STATUS_PARAMETER_ERROR The video was interrupted or failed to play due to an error.

If you specified the Virtual Currency requester with the request, an automatic request is triggered to the Virtual Currency Server as soon as the video is finished.