Skip to content

Exoplayer IMA module, I find it strange to implement play/pause an ad(client side) by user click action only using exoplayer default google ima layout #2704

@jerrylkc

Description

@jerrylkc
Image Image

My original code is to pause an google ima ad(client side) and resume an ad when user click the play/pause button only.

The play/pause button should be in exoplayer build-in default google ima layout (id:exo_play_pause?),

I use below code to pause/resume an ad by user action and it works.

 adsLoader = adsBuilder.setImaSdkSettings(imaSdkSettings)
                        .setVideoAdPlayerCallback(new VideoAdPlayer.VideoAdPlayerCallback() {

                            @Override
                            public void onPause(AdMediaInfo adMediaInfo) {
                                    if (player!=null){
                                        player.pause();
                                    }
                            }

                            @Override
                            public void onResume(AdMediaInfo adMediaInfo) {
                                if (player!=null){
                                        player.play();
                                    }
                            }

But the problem is many case can trigger onPause not only user click play/pause action
(e.g when user click skip button, onPause will also be called)

I find AdEventListener, AdEvent PAUSED/RESUMED will be called when user click play/pause button.

               .setAdEventListener(new AdEvent.AdEventListener() {
                            @Override
                            public void onAdEvent(@NonNull AdEvent adEvent) {
                                 switch (adEvent.getType()) {
                                    case PAUSED:
                                        if (player!=null){
                                            player.pause();
                                       }
                                        break;
                                    case RESUMED:
                                        if (player!=null){
                                            player.play();
                                       }                          

The above code works when user click a pause button, a PAUSED adEvent received , an ad can be paused, and many subsequent AD_PROGRESS adEvents are keeping received.

but when user click a play button, a RESUMED adEvent is received, the ad is played again, but immediately a subsequent PAUSED adEvent is received, and the ad is paused again.

Anything wrong about my implementation?
do AdEvent RESUMED/PASUED indicatie only user click pause/play button?
Is there any function that I can capture when user click play/pause button only?

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions