ExoPlayer icon indicating copy to clipboard operation
ExoPlayer copied to clipboard

I am unable to set adsMediaSource.

Open prernagp opened this issue 7 years ago • 2 comments

My layout file is:- <com.google.android.exoplayer2.ui.PlayerView android:id="@+id/video_view" android:layout_width="match_parent" android:layout_height="match_parent" app:resize_mode="fill" />

I am trying to build adsMediaSource object like this:-

private PlayerView mPlayerView; return new AdsMediaSource( mediaSource, defaultHttpDataSourceFactory, adsLoader, mPlayerView.getOverlayFrameLayout());

But, when I do above, I am getting:-

Cast 4th parameter, to AdsLoader.AdViewProvider. So, when i cast it and do the following:- return new AdsMediaSource( mediaSource, defaultHttpDataSourceFactory, adsLoader, (AdsLoader.AdViewProvider) mPlayerView.getOverlayFrameLayout()); It throws error,

java.lang.ClassCastException: android.widget.FrameLayout cannot be cast to com.google.android.exoplayer2.source.ads.AdsLoader$AdViewProvider

prernagp avatar Oct 01 '19 05:10 prernagp

As you already noted the fourth parameter is an AdsLoader.AdViewProvider interface and you need to implement that instead of passing in the overlay frame layouy directly. If you are using the PlayerView class of our UI module, you can just pass in that because it already implements the interface.

tonihei avatar Oct 02 '19 10:10 tonihei

I'm using the PlayerView from com.google.android.exoplayer2.ui package, still i get this crash when i use playerView.getOverlayFrameLayout() and cast it to AdsLoader.AdViewProvider. Any idea why?

my xml:

<com.google.android.exoplayer2.ui.PlayerView
        android:id="@+id/VideoPlayerView"
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="1.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="1.0"/>
   

Java:

playerView = findViewById(R.id.VideoPlayerView);
playerView.setFocusable(true);
playerView.setPlayer(player);
playerView.setShowBuffering(true);
 AdsMediaSource adsMediaSource = new AdsMediaSource(
                mediaSource,
                dataSourceFactory,
                imaAdsLoader,
                (AdsLoader.AdViewProvider) playerView.getOverlayFrameLayout()
        );

I'm using exoplayer 2.10

ramim94 avatar Nov 20 '19 17:11 ramim94