Esempio n. 1
0
        private IMediaSource CreateAdsMediaSource(IMediaSource mediaSource, android.Net.Uri adTagUri)
        {
            // Load the extension source using reflection so the demo app doesn't have to depend on it.
            // The ads loader is reused for multiple playbacks, so that ad playback can resume.
            try
            {
                Class loaderClass = Class.ForName("com.google.android.exoplayer2.ext.ima.ImaAdsLoader");
                if (adsLoader == null)
                {
                    Constructor loaderConstructor = loaderClass.AsSubclass(Class.FromType(typeof(IAdsLoader))).GetConstructor(Class.FromType(typeof(Context)), Class.FromType(typeof(android.Net.Uri)));

                    adsLoader     = (IAdsLoader)loaderConstructor.NewInstance(this, adTagUri);
                    adUiViewGroup = new FrameLayout(this);
                    // The demo app has a non-null overlay frame layout.
                    playerView.OverlayFrameLayout.AddView(adUiViewGroup);
                }
                AdMediaSourceFactory adMediaSourceFactory = new AdMediaSourceFactory(this);

                return(new AdsMediaSource(mediaSource, adMediaSourceFactory, adsLoader, adUiViewGroup));
            }
            catch (ClassNotFoundException e)
            {
                // IMA extension not loaded.
                return(null);
            }
            catch (Java.Lang.Exception e)
            {
                throw new RuntimeException(e);
            }
        }
Esempio n. 2
0
 private void ReleaseAdsLoader()
 {
     if (adsLoader != null)
     {
         adsLoader.Release();
         adsLoader      = null;
         loadedAdTagUri = null;
         playerView.OverlayFrameLayout.RemoveAllViews();
     }
 }