예제 #1
0
        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);
            }
        }
예제 #2
0
        private IMediaSource CreateMediaSourceWithAds(IMediaSource videoSource, Uri imAdsUri)
        {
            try
            {
                Player = ExoPlayerFactory.NewSimpleInstance(ActivityContext);
                SimpleExoPlayerView.Player = Player;

                if (ImaAdsLoader == null)
                {
                    var imaSdkSettings = ImaSdkFactory.Instance.CreateImaSdkSettings();
                    imaSdkSettings.AutoPlayAdBreaks = true;
                    imaSdkSettings.DebugMode        = true;

                    ImaAdsLoader = new ImaAdsLoader.Builder(ActivityContext)
                                   .SetImaSdkSettings(imaSdkSettings)
                                   .SetMediaLoadTimeoutMs(30 * 1000)
                                   .SetVastLoadTimeoutMs(30 * 1000)
                                   .BuildForAdTag(imAdsUri); // here is url for vast xml file

                    ImaAdsLoader.SetPlayer(Player);

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

                    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);
            }
        }