Documentation

❗️

Deprecated

RichMedia ad type was deprecated in version 2.5.1

πŸ“˜

API added in version 1.8.0

RichMediaRequest

Setup RichMediaRequest builder

To create a RichMediaRequest instance, you need to create a RichMediaRequest.Builder instance, set all the necessary parameters and call build on it.

RichMediaRequest.Builder richMediaRequestBuilder = new RichMediaRequest.Builder()
        .setTargetingParams(...) // Set TargatingParams instance
        .setPriceFloorParams(...) // Set price floor parameters
        .setSessionAdParams(...) // Set SessionAdParams instance
        .setLoadingTimeOut(...) // Set loading timeout in milliseconds
        .setPlacementId(...) // Set placement id
val richMediaRequestBuilder = RichMediaRequest.Builder()
        .setTargetingParams(...) // Set TargatingParams instance
        .setPriceFloorParams(...) // Set price floor parameters
        .setSessionAdParams(...) // Set SessionAdParams instance
        .setLoadingTimeOut(...) // Set loading timeout in milliseconds
        .setPlacementId(...) // Set placement id

Set AdRequestListener

Set the RichMediaRequest.AdRequestListener instance to theRichMediaRequest.Builder instance.

richMediaRequestBuilder.setListener(new RichMediaRequest.AdRequestListener() {
    
    /**
     * Called when RichMediaRequest was requested successfully
     *
     * @param request       - RichMediaRequest instance
     * @param auctionResult - AuctionResult info
     */
    @Override
    public void onRequestSuccess(@NonNull RichMediaRequest request,
                                 @NonNull AuctionResult auctionResult) {

    }

    /**
     * Called when RichMediaRequest request failed
     *
     * @param request - RichMediaRequest instance
     * @param error   - BMError with additional info about error
     */
    @Override
    public void onRequestFailed(@NonNull RichMediaRequest request,
                                @NonNull BMError error) {
        
    }

    /**
     * Called when RichMediaRequest expired
     *
     * @param request - RichMediaRequest instance
     */
    @Override
    public void onRequestExpired(@NonNull RichMediaRequest request) {
        
    }
  
});
richMediaRequestBuilder.setListener(object : RichMediaRequest.AdRequestListener {
    
    /**
     * Called when RichMediaRequest was requested successfully
     *
     * @param request       - RichMediaRequest instance
     * @param auctionResult - AuctionResult info
     */
    override fun onRequestSuccess(request: RichMediaRequest,
                                  auctionResult: AuctionResult) {

    }

    /**
     * Called when RichMediaRequest request failed
     *
     * @param request - RichMediaRequest instance
     * @param error   - BMError with additional info about error
     */
    override fun onRequestFailed(request: RichMediaRequest,
                                 error: BMError) {

    }

    /**
     * Called when RichMediaRequest expired
     *
     * @param request - RichMediaRequest instance
     */
    override fun onRequestExpired(request: RichMediaRequest) {

    }
  
})

🚧

Note

AdRequestListener callbacks are delivered on the background thread, not the main one.

Build RichMediaRequest

When all the necessary parameters are set, call build on the RichMediaRequest.Builder instance:

RichMediaRequest richMediaRequest = richMediaRequestBuilder.build();
val richMediaRequest = richMediaRequestBuilder.build()

❗️

Keep ad request

You need to keep reference to RichMediaRequest before calling RichMediaRequest#request, otherwise it is possible it will be cleared by Garbage Collector and callbacks won’t be triggered.

Request RichMediaRequest

When you need to request an ad and get an AuctionResult, call request on the RichMediaRequest instance.

richMediaRequest.request(...);
richMediaRequest.request(...)

πŸ“˜

When you made an in-house meditation and you decided that an advertisement from BidMachine will be shown - call richMediaRequest.notifyMediationWin, if BidMachine lost in mediation - call richMediaRequest.notifyMediationLoss

Destroy RichMediaRequest

Destroy the RichMediaRequest instance if you don't need it anymore.

richMediaRequest.destroy();
richMediaRequest.destroy()

❗️

Don't destroy the RichMediaRequest instance, if it will be used for load the RichMediaView instance or if the RichMediaView instance loaded with the RichMediaRequest instance has not been shown yet.

Otherwise, ad will not work correctly, which can affect a lower display rate, fill rate, rendering errors, and as a result - lower revenue.

RichMediaView

Load RichMediaView

When you would like to load and display requested Ads:

  • Make sure that the RichMediaRequest instance have AuctionResult. It's mean ads requested successfully.
richMediaRequest.getAuctionResult() != null
richMediaRequest.auctionResult != null
  • Make sure that theRichMediaRequest instance not expired.
!richMediaRequest.isExpired()
!richMediaRequest.isExpired

Before execute load on the RichMediaView instance set the RichMediaListener instance:

RichMediaView richMediaView = new RichMediaView(...);
richMediaView.setLayoutParams(...);
richMediaView.setListener(new RichMediaListener() {
    
    /**
     * Called when Ad was loaded and ready to be displayed
     *
     * @param ad - RichMediaView instance
     */
    @Override
    public void onAdLoaded(@NonNull RichMediaView ad) {

    }

    /**
     * Called when Ad failed to load
     *
     * @param ad    - RichMediaView instance
     * @param error - BMError with additional info about error
     */
    @Override
    public void onAdLoadFailed(@NonNull RichMediaView ad,
                               @NonNull BMError error) {

    }

    /**
     * Called when Ad Impression has been tracked
     *
     * @param ad - RichMediaView instance
     */
    @Override
    public void onAdImpression(@NonNull RichMediaView ad) {

    }
  
    /**
     * Called when Ad show failed
     *
     * @param ad    - RichMediaView instance
     * @param error - BMError with additional info about error
     */
    @Override
    public void onAdShowFailed(@NonNull RichMediaView ad,
                               @NonNull BMError error) {
    
    }
  
    /**
     * Called when Ad has been clicked
     *
     * @param ad - RichMediaView instance
     */
    @Override
    public void onAdClicked(@NonNull RichMediaView ad) {

    }

    /**
     * Called when Ad expired
     *
     * @param ad - RichMediaView instance
     */
    @Override
    public void onAdExpired(@NonNull RichMediaView ad) {

    }
  
});
richMediaView.load(richMediaRequest);
val richMediaView = RichMediaView(...)
richMediaView.setLayoutParams(...)
richMediaView.setListener(object : RichMediaListener {
    
    /**
     * Called when Ad was loaded and ready to be displayed
     *
     * @param ad - RichMediaView instance
     */
    override fun onAdLoaded(ad: RichMediaView) {

    }

    /**
     * Called when Ad failed to load
     *
     * @param ad    - RichMediaView instance
     * @param error - BMError with additional info about error
     */
    override fun onAdLoadFailed(ad: RichMediaView,
                                error: BMError) {

    }

    /**
     * Called when Ad Impression has been tracked
     *
     * @param ad - RichMediaView instance
     */
    override fun onAdImpression(ad: RichMediaView) {

    }
    
    /**
     * Called when Ad show failed
     *
     * @param ad    - RichMediaView instance
     * @param error - BMError with additional info about error
     */
    override fun onAdShowFailed(ad: RichMediaView,
                                error: BMError) {
    
    }
    
    /**
     * Called when Ad has been clicked
     *
     * @param ad - RichMediaView instance
     */
    override fun onAdClicked(ad: RichMediaView) {

    }

    /**
     * Called when Ad expired
     *
     * @param ad - RichMediaView instance
     */
    override fun onAdExpired(ad: RichMediaView) {

    }
  
})
richMediaView.load(richMediaRequest)

Use onAdLoaded callback to determine the possibility of displaying

Show RichMediaView

Before displaying, check if the RichMediaView instance can be displayed:

richMediaView.canShow();
richMediaView.canShow()

To display the RichMediaView instance, you just need to add it to the layout.

viewGroup.removeAllViews();
viewGroup.addView(richMediaView);
viewGroup.removeAllViews()
viewGroup.addView(richMediaView)

🚧

Don't forget set LayoutParams to RichMediaView before show it.

RichMediaView control playback

RichMediaView has several methods to control playback.

  • resume - RichMediaView is on screen and playback should resume
richMediaView.resume();
richMediaView.resume()
  • pause - RichMediaView is out of screen and playback should pause
richMediaView.pause();
richMediaView.pause()
  • mute - to mute the sound in RichMediaView
richMediaView.mute();
richMediaView.mute()
  • unmute - to unmute the sound in RichMedia
richMediaView.unmute();
richMediaView.unmute()

Destroy RichMediaView

After ad was successful shown and no longer needed, it can be destroyed.

richMediaView.destroy();
richMediaView.destroy()

πŸ“˜

Sample

You can find code examples written in Java and Kotlin: Github RichMedia