コード例 #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);
            }
        }
コード例 #2
0
ファイル: VideoController.cs プロジェクト: divitiae/playtube
        private IMediaSource CreateMediaSourceWithAds(IMediaSource videoSource, Uri imAdsUri)
        {
            try
            {
                // Player = ExoPlayerFactory.NewSimpleInstance(ActivityContext);
                SimpleExoPlayerView.Player = Player;

                if (ImaAdsLoader == null)
                {
                    //ImaAdsLoader = new ImaAdsLoader(ActivityContext, imAdsUri);
                    var imaSdkSettings = ImaSdkFactory.Instance.CreateImaSdkSettings();
                    imaSdkSettings.AutoPlayAdBreaks = true;
                    imaSdkSettings.DebugMode        = true;

                    IAdDisplayContainer a = ImaSdkFactory.Instance.CreateAdDisplayContainer();
                    a.AdContainer = MainVideoFrameLayout;
                    ImaAdsLoader  = new ImaAdsLoader(ActivityContext, imAdsUri);
                    ImaAdsLoader.SetPlayer(Player);

                    AdMediaSourceFactory adMediaSourceFactory = new AdMediaSourceFactory(this);

                    IMediaSource mediaSourceWithAds = new AdsMediaSource(
                        videoSource,
                        adMediaSourceFactory,
                        ImaAdsLoader,
                        SimpleExoPlayerView);

                    //Player.Prepare(mediaSourceWithAds);
                    //Player.AddListener(PlayerListener);
                    //Player.PlayWhenReady = true;

                    return(mediaSourceWithAds);
                }

                return(new AdsMediaSource(videoSource, new AdMediaSourceFactory(this), ImaAdsLoader, SimpleExoPlayerView));
            }
            catch (ClassNotFoundException e)
            {
                Console.WriteLine(e.Message);
                // IMA extension not loaded.
                return(null);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(null);
            }
        }