Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Ima SDK, sound playing but no view

I'm trying to play ads on Android using the Google IMA sdk. I used the example app to come to my solution but for some reason I only get the audio of the ad and the overlay (ad length, read more button etc.). The video is not playing, or at least invisible.

I build up the video player using the VideoView:

package eu.myapp.test.views;

import android.media.MediaPlayer;
import android.view.View;
import android.view.ViewGroup;
import android.widget.MediaController;
import android.widget.VideoView;
import android.media.MediaPlayer.OnCompletionListener;
import android.media.MediaPlayer.OnErrorListener;
import android.media.MediaPlayer.OnInfoListener;

import com.facebook.react.uimanager.ThemedReactContext;

import java.util.ArrayList;
import java.util.List;

import eu.myapp.test.controllers.PlayerController;


public class PlayerView extends VideoView {
private PlayerController mPlayerController;

public PlayerView(ThemedReactContext context, PlayerController playerController) {
    super(context);
    mPlayerController = playerController;
    init();
}

private void init() {
    MediaController mediaController = new MediaController(getContext());
    mediaController.setAnchorView(this);
    setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));

    super.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
        @Override
        public void onPrepared(MediaPlayer mp) {
            mp.start();
        }
    });

    super.setOnCompletionListener(new OnCompletionListener() {
        @Override
        public void onCompletion(MediaPlayer mediaPlayer) {
            mediaPlayer.reset();
            reset();
        }
    });


    super.setOnErrorListener(new OnErrorListener() {
        @Override
        public boolean onError(MediaPlayer mp, int what, int extra) {
            mp.reset();
            reset();

            return true;
        }
    });

    super.setOnInfoListener(new OnInfoListener() {
        @Override
        public boolean onInfo(MediaPlayer mp, int what, int extra) {
            // When video starts, make progressbar visible and spinner invisible
            if (MediaPlayer.MEDIA_INFO_VIDEO_RENDERING_START == what) {
                mPlayerController.setProgressBarVisibility(View.VISIBLE);
                mPlayerController.setPlaceholderVisibility(View.GONE);
                mPlayerController.setAdSpinnerVisibility(View.GONE);
                return true;
            }

            return false;
        }
    });

    mPlayerController.addPlayerView(this);
}

public void play() {
    start();
}

public void reset() {
    mPlayerController.setProgressBarVisibility(View.GONE);
    mPlayerController.setPlaceholderVisibility(View.VISIBLE);
    mPlayerController.setAdSpinnerVisibility(View.VISIBLE);
    mPlayerController.onVideoComplete();
}
}

Is anyone familiar with this issue?

EDIT: after completion I get a

playerstate error (-38, 0).

But I doubt this is the problem since it's not working from the beginning.

The issue is does not occur, or is rare on some devices. While it always appears on other devices.

like image 384
Nieck Avatar asked Oct 16 '22 13:10

Nieck


1 Answers

Fixed it. I had a SurfaceView for my normal video and a VideoView for the Ad. The SurfaceView showed on top of the VideoView which caused the ad to be invisible.

like image 85
Nieck Avatar answered Nov 15 '22 05:11

Nieck