androidx / androidx/media

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

Open
#2,704 1 comment 0 reactions 1 assignee View on GitHub

@marcbaechinger is already working on this.

Since Aug 7, 2025.

needs triage question
Dominant language
Java
Stars
3k
Forks
955
Avg merge
12d 14h
Merged PRs (30d)
2

Description

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?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.