How to play IMA ads on Chromecast from sender app ( Android )

303 Views Asked by At

Hi everyone just wondering if anyone knew what we need to do to play IMA ads on chrome cast from a sender app, From what I understand reading the docs the only way to play it is to send a message to the chromecast receiver with the pubads URL:

private void loadMedia(MediaInfo mediaInfo, Boolean autoplay) {
    try {
        Log.d(TAG, "loading media");
        mRemoteMediaPlayer.load(sApiClient, mediaInfo, autoplay)
                .setResultCallback(new ResultCallback<RemoteMediaPlayer.MediaChannelResult>() {
                    @Override
                    public void onResult(RemoteMediaPlayer.MediaChannelResult result) {
                        if (result.getStatus().isSuccess()) {
                            boolean adStarted = mVideoPlayerController.hasAdStarted();
                            if (mVideoFragment.isVmap() || !adStarted) {
                                sendMessage("requestAd," + mAdTagUrl + ","
                                        + mVideoPlayerController.getCurrentContentTime());
                            } else {
                                sendMessage("seek,"
                                    + mVideoPlayerController.getCurrentContentTime());
                            }
                        } else {
                            Log.e(TAG, "Error loading Media : "
                                    + result.getStatus().getStatusCode());
                        }

FYI : the mAdTagUrl is the 'pubads' link

Ex pubs link :

https://pubads.g.doubleclick.net/gampad/ads?sz=640x480&iu=/124319096/external/single_ad_samples&ciu_szs=300x250&impl=s&gdfp_req=1&env=vp&output=vast&unviewed_position_start=1&cust_params=deployment%3Ddevsite%26sample_ct%3Dskippablelinear&correlator=
1

There are 1 best solutions below

3
Manendra De Mel On

Incase anyone was looking for the answer :

it's actually in the AdBreak Clip Info Builder -> setVastAdsRequest() Method.

Pass in the 'pubads' link to this method , and you're good to go.