В теге Android Tv Vast реклама не загружается - PullRequest
0 голосов
/ 25 марта 2020

Я хочу показывать рекламу на телевидении с помощью spotx. Я использую BrightcovePlayer для видео. Я успешно внедрил SpotxAndroidSDK, но при запуске видеообъявлений не отображается только объем, а значок воспроизведения (из объявлений) отображает содержание объявлений, а не загружается. Но в android Устройство работает правильно, но в телевизионном приложении оно не работает.

Пример демонстрации Spotx Ссылка: https://github.com/spotxmobile/spotx-demo-android enter image description here

BrightcovePlayerActivity. Java

public class BrightcovePlayerActivity extends BrightcovePlayer {


    private BrightcoveVideoView _videoView;
    private EventEmitter _eventEmitter;
    private boolean _hasSetCuePoints;

    private Settings _settings;


    private RelativeLayout _layout;
    private Rect _layoutPadding;
    private Drawable _layoutBackground;
    private RelativeLayout.LayoutParams _videoLayoutParams;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_brightcove_player);

        _layout = (RelativeLayout)findViewById(R.id.brightcove_layout);


        _settings = new Settings(this);
        _settings.set(Settings.KEY_CHANNEL_ID, Settings.DEFAULT_CHANNEL_ID);
        _videoView = (BrightcoveVideoView) findViewById(R.id.brightcove_video_view);
        brightcoveVideoView = _videoView;
    }

    @Override
    protected void onStart() {
        super.onStart();

        setup();
        loadContent();
        _videoView.start();
    }

    /**
     * Sets up the BrightcoveVideoView and SpotX.
     */
    private void setup() {
        // video view
        _eventEmitter = _videoView.getEventEmitter();

        // spotx

        SpotXAdRequest request = _settings.requestWithSettings();
        try {
            Log.e("REQUEST_PARAM_JSON",request.getParamJSON().toString());
            Log.e("REQUEST_PAYBACK_JSON",request.getPlaybackJSON().toString());
        } catch (JSONException e) {
            e.printStackTrace();
        }
        new SpotXBrightcoveAdapter(_eventEmitter, _videoView, request);

        // listen for the content source to be set to create ad cue points
        _eventEmitter.on(EventType.DID_SET_SOURCE, new EventListener() {
            @Override
            public void processEvent(Event event) {
                Source source = (Source) event.properties.get(Event.SOURCE);
                setupCuePoints(source);
            }
        });

        _eventEmitter.on(EventType.ENTER_FULL_SCREEN, new EventListener() {
            @Override
            public void processEvent(Event event) {
                enterFullscreen();
            }
        });

        _eventEmitter.on(EventType.DID_EXIT_FULL_SCREEN, new EventListener() {
            @Override
            public void processEvent(Event event) {
                exitFullscreen();
            }
        });
    }

    private void enterFullscreen() {
        // Remove padding

        _layoutPadding = new Rect(_layout.getPaddingLeft(), _layout.getPaddingTop(),
                _layout.getPaddingRight(), _layout.getPaddingBottom());
        _layout.setPadding(0, 0, 0, 0);

        // Change background to black
        _layoutBackground = _layout.getBackground();
        _layout.setBackgroundColor(Color.BLACK);

        // Set video player to fill parent
        _videoLayoutParams = (RelativeLayout.LayoutParams)_videoView.getLayoutParams();
        RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);

        _videoView.setLayoutParams(layoutParams);
    }

    private void exitFullscreen() {
        // Reset padding

        _layout.setPadding(_layoutPadding.left, _layoutPadding.top,
                _layoutPadding.right, _layoutPadding.bottom);

        // Set background back to white
        _layout.setBackground(_layoutBackground);

        // Restore video player size
        _videoView.setLayoutParams(_videoLayoutParams);
    }

    /**
     * Creates the Video from the given MP4 and puts the content in the BrightcoveVideoView.
     */
    private void loadContent() {
        Video bigBuckBunnyVideo = Video.createVideo("https://spotxchange-a.akamaihd.net/media/videos/orig/d/3/d35ba3e292f811e5b08c1680da020d5a.mp4");
        _videoView.add(bigBuckBunnyVideo);
    }

    /**
     * Creates the CuePoints at points in time relative to the content video on when an Ad will play.
     *
     * @param source
     */
    private void setupCuePoints(Source source) {
        if (_hasSetCuePoints) {
            return;
        }
        _hasSetCuePoints = true;
        final String cuePointType = "AD";
        CuePoint cuePoint;
        Map<String, Object> properties = new HashMap<>();

        // create a pre-roll
        cuePoint = new CuePoint(CuePoint.PositionType.BEFORE, cuePointType, Collections.<String, Object>emptyMap());
        properties.put(Event.CUE_POINT, cuePoint);
        _eventEmitter.emit(EventType.SET_CUE_POINT, properties);

        // create a mid-roll at the 15 second mark (mid-rolls don't work with HLS videos due to an Android bug).
        if (!DeliveryType.HLS.equals(source.getProperties().get(SourceAwareMetadataObject.Fields.DELIVERY_TYPE))) {
            cuePoint = new CuePoint(15000, cuePointType, Collections.<String, Object>emptyMap());
            properties.put(Event.CUE_POINT, cuePoint);
            _eventEmitter.emit(EventType.SET_CUE_POINT, properties);
        }

        // create a post-roll
        cuePoint = new CuePoint(CuePoint.PositionType.AFTER, cuePointType, Collections.<String, Object>emptyMap());
        properties.put(Event.CUE_POINT, cuePoint);
        _eventEmitter.emit(EventType.SET_CUE_POINT, properties);
    }

}

Настройки. java

public class Settings {

    // Application API key
    // public static final String API_KEY                  = "11111111111111111111111111111111";

    public static final String API_KEY                  = "5234263959aefb4763ed22c7ea422beb";
    // Default channel
    public static final String DEFAULT_CHANNEL_ID       = "85394";

    // Standard preferences
    public static final String KEY_CHANNEL_ID           = "spotxChannel";
    public static final String KEY_PRESENTATION         = "spotxPresentationType";

    public static final String KEY_VPAID                = "spotxUseVPAID";

    public static final String KEY_POD_ENABLE           = "spotxUsePodding";
    public static final String KEY_POD_COUNT            = "spotxAdCount";
    public static final String KEY_AD_DURATION          = "spotxAdDuration";
    public static final String KEY_POD_DURATION         = "spotxPodDuration";

    public static final String KEY_GDPR_ENABLE          = "spotxGDPREnable";
    public static final String KEY_GDPR_CONSENT         = "spotxGDPRConsent";

    // MoPub Ad Units
    public static final String KEY_MOPUB_INTERSTITIAL   = "spotxMoPubI";
    public static final String KEY_MOPUB_REWARDED       = "spotxMoPubR";

    // GMA IDs
    public static final String KEY_GMA_INTERSTITIAL     = "spotxGmaI";
    public static final String KEY_GMA_REWARDED         = "spotxGmaR";



    private SharedPreferences _pref;

    /** New Settings object with the given context. */
    public Settings(Context context) {
        _pref = PreferenceManager.getDefaultSharedPreferences(context);
    }
    /**
     * Creates a SpotXAdRequest with standard settings applied to it.
     *
     * @return the ad request.
     * */
    public SpotXAdRequest requestWithSettings() {
        SpotXAdRequest request = new SpotXAdRequest(API_KEY);
        request.channel = "85394";

        // This is how to use VPAID
        if (getBoolean(KEY_VPAID)) {
            request.putParam("VPAID", "js");
        }



        // This is how to set up podding
        if (getBoolean(KEY_POD_ENABLE)) {
            int podSize = Integer.parseInt(getString(KEY_POD_COUNT));
            int adDuration = Integer.parseInt(getString(KEY_AD_DURATION));
            int podDuration = Integer.valueOf(getString(KEY_POD_DURATION));

            request.putCustom("pod[size]", podSize);
            request.putCustom("pod[max_ad_dur]", adDuration);
            request.putCustom("pod[max_pod_dur]", podDuration);
        }

        // This is how to enable GDPR with a consent string:
        if (getBoolean(KEY_GDPR_ENABLE)) {
            String gdprConsent = getString(KEY_GDPR_CONSENT);

            SharedPreferences.Editor editor = _pref.edit();
            editor.putString("IABConsent_SubjectToGDPR", "1");
            editor.putString("IABConsent_ConsentString", gdprConsent);
            editor.commit();
        } else {
            // Need to remove GDPR from the SharedPreferences, or they'll be used the next time the demo is run
            SharedPreferences.Editor editor = _pref.edit();
            editor.remove("IABConsent_SubjectToGDPR");
            editor.remove("IABConsent_ConsentString");
            editor.commit();
        }



        return request;
    }

    /** Retrieves a string value with a default. */
    public String getString(String name, String defValue) {
        String res = _pref.getString(name, defValue);
        if (res == null || res.length() == 0) {
            res = defValue;
        }
        return res;
    }

    /** Retrieves a string value. */
    public String getString(String name) {
        return _pref.getString(name, "");
    }

    /** Retrieves a boolean value with a default. */
    public Boolean getBoolean(String name, boolean defValue) {
        return _pref.getBoolean(name, defValue);
    }

    /** Retrieves a boolean value with default = false. */
    public Boolean getBoolean(String name) {
        return _pref.getBoolean(name, false);
    }

    /** Retrieves an integer value. */
    public Integer getInt(String name) {
        return _pref.getInt(name, 0);
    }

    /** Sets a string value. */
    public void set(String name, String value) {
        SharedPreferences.Editor editor = _pref.edit();
        if (value == null) {
            editor.remove(name);
        } else {
            editor.putString(name, value);
        }
        editor.commit();
    }

    /** Sets a boolean value. */
    public void set(String name, Boolean value) {
        SharedPreferences.Editor editor = _pref.edit();
        if (value == null) {
            editor.remove(name);
        } else {
            editor.putBoolean(name, value);
        }
        editor.commit();
    }

    /** Sets an integer value. */
    public void set(String name, Integer value) {
        SharedPreferences.Editor editor = _pref.edit();
        if (value == null) {
            editor.remove(name);
        } else {
            editor.putInt(name, value);
        }
        editor.commit();
    }

}

build.gradle

apply plugin: 'com.android.application'
apply plugin: 'com.google.firebase.crashlytics'
apply plugin: 'com.google.gms.google-services'  // Google Services plugin

repositories {
    mavenCentral()
    jcenter()
    google()
    maven {
        url 'http://repo.brightcove.com/releases'
    }
}

android {
    compileSdkVersion 29
    defaultConfig {
        applicationId "i.com.myapplication"
        minSdkVersion 21
        targetSdkVersion 29
        versionCode 1
        versionName "1.0.1"
        vectorDrawables.useSupportLibrary = true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {
    def withoutExoPlayer = { exclude group: 'com.google.android.exoplayer', module: 'exoplayer' }

    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.leanback:leanback:1.0.0'
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'com.github.bumptech.glide:glide:3.8.0'
    implementation 'com.google.firebase:firebase-analytics:17.2.2'

    implementation 'com.google.android.exoplayer:exoplayer:2.8.+'
    implementation 'com.google.android.exoplayer:extension-leanback:2.8.+'

    implementation 'androidx.leanback:leanback-preference:1.0.0'
    implementation 'com.squareup.picasso:picasso:2.5.2'
    implementation 'com.google.firebase:firebase-crashlytics:17.0.0-beta01'
    implementation 'com.google.ads.interactivemedia.v3:interactivemedia:3.18.0'

    implementation 'com.spotxchange:spotx-sdk-android:4.5.0', withoutExoPlayer
    implementation 'com.brightcove.player:android-sdk:4.13.7'
    implementation 'com.google.android.gms:play-services-base:16.0.1'
    implementation 'com.google.android.gms:play-services-ads:16.0.0'

    testImplementation 'junit:junit:4.12'
    testImplementation 'org.robolectric:robolectric:4.2.1'
    implementation 'androidx.media2:media2-exoplayer:1.0.3'


}
...