コード例 #1
0
        public void Play(string url)
        {
            if (clicks % 2 == 0)
            {
                #region ExoPlayer

                var mediaUrl = url;
                var mediaUri = Android.Net.Uri.Parse(mediaUrl);
                Android.Content.Context context = Android.App.Application.Context;
                var userAgent = Util.GetUserAgent(context, "InstationPlayer");
                var defaultHttpDataSourceFactory  = new DefaultHttpDataSourceFactory(userAgent);
                var defaultDataSourceFactory      = new DefaultDataSourceFactory(context, null, defaultHttpDataSourceFactory);
                var extractorMediaSource          = new ExtractorMediaSource(mediaUri, defaultDataSourceFactory, new DefaultExtractorsFactory(), null, null);
                var defaultBandwidthMeter         = new DefaultBandwidthMeter();
                var adaptiveTrackSelectionFactory = new AdaptiveTrackSelection.Factory(defaultBandwidthMeter);
                var defaultTrackSelector          = new DefaultTrackSelector(adaptiveTrackSelectionFactory);

                exoPlayer = ExoPlayerFactory.NewSimpleInstance(context, defaultTrackSelector);
                exoPlayer.Prepare(extractorMediaSource);
                Console.WriteLine("Prepared");
                exoPlayer.PlayWhenReady = true;
                Console.WriteLine("Started");
                clicks++;

                #endregion
            }
            else if (clicks % 2 != 0)
            {
                exoPlayer.Stop();
                Console.WriteLine("Paused");
                clicks++;
            }
        }
コード例 #2
0
        public void playVideo(string url, string typestream)
        {
            var MyURL    = url;
            var mediaUri = Android.Net.Uri.Parse(MyURL);

            var userAgent = Util.GetUserAgent(this, "Player");
            var defaultHttpDataSourceFactory = new DefaultHttpDataSourceFactory(userAgent);
            var defaultDataSourceFactory     = new DefaultDataSourceFactory(this, null, defaultHttpDataSourceFactory);

            if (typestream == "HLS")
            {
                playerView.UseController = false;
                extractorMediaSource     = new HlsMediaSource.Factory(defaultDataSourceFactory).CreateMediaSource(mediaUri);
            }
            else if (typestream == "MP4")
            {
                extractorMediaSource = new ExtractorMediaSource(mediaUri, defaultDataSourceFactory, new DefaultExtractorsFactory(), null, null);
            }
            ConcatenatingMediaSource concatenatedSource =
                new ConcatenatingMediaSource(extractorMediaSource);
            var defaultBandwidthMeter         = new DefaultBandwidthMeter();
            var adaptiveTrackSelectionFactory = new AdaptiveTrackSelection.Factory(defaultBandwidthMeter);
            var defaultTrackSelector          = new DefaultTrackSelector(adaptiveTrackSelectionFactory);

            player = ExoPlayerFactory.NewSimpleInstance(this, defaultTrackSelector);

            player.Prepare(concatenatedSource);

            player.AddListener(new CustomListener());

            playerView.Player = player;

            player.PlayWhenReady = true;
        }
コード例 #3
0
 public EventLogger(DefaultTrackSelector trackSelector)
 {
     this.trackSelector = trackSelector;
     window             = new Timeline.Window();
     period             = new Timeline.Period();
     startTimeMs        = SystemClock.ElapsedRealtime();
 }
コード例 #4
0
        protected override void OnElementChanged(ElementChangedEventArgs <ExtendedVideoPlayer> e)
        {
            base.OnElementChanged(e);

            string s = Element.Source;

            //
            // Will be invoked by the Xamarin.Forms page when the last is closed
            //
            Element.ReleaseAction = PlayerRelease;

            _exoSpot = new PlayerView(Context);
            //
            // Video will be expanded on full screen
            //
            _exoSpot.SetResizeMode(AspectRatioFrameLayout.ResizeModeFit);

            SetNativeControl(_exoSpot);

            //
            // Create a default TrackSelector
            //
            Handler         mainHandler    = new Handler();
            IBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();

            AdaptiveTrackSelection.Factory videoTrackSelectionFactory =
                new AdaptiveTrackSelection.Factory(bandwidthMeter);

            TrackSelector trackSelector =
                new DefaultTrackSelector(videoTrackSelectionFactory);

            //
            // Create the player
            //
            _exoPlayer =
                ExoPlayerFactory.NewSimpleInstance(Context, trackSelector);
            _exoPlayer.AddListener(new ExtendedVideoPlayerEventListener(_exoPlayer));
            _exoPlayer.PlayWhenReady = true;

            //
            // Attach player to the view
            //
            _exoSpot.Player = _exoPlayer;

            DefaultDataSourceFactory dataSourceFactory = new DefaultDataSourceFactory(Context,
                                                                                      Util.GetUserAgent(Context, Context.GetString(Resource.String.application_name)));

            IMediaSource videoSource = new ExtractorMediaSource(
                Android.Net.Uri.Parse(Element.Source),
                new CacheableDataSource(Context, 100 * 1024 * 1024, 5 * 1024 * 1024),
                new DefaultExtractorsFactory(),
                null,
                null);

            //
            // Prepare the player with the source.
            //
            _exoPlayer.Prepare(videoSource);
        }
コード例 #5
0
        public void InitializePlayer()
        {
            var userAgent = Util.GetUserAgent(this, "Player");
            var defaultHttpDataSourceFactory  = new DefaultHttpDataSourceFactory(userAgent);
            var defaultBandwidthMeter         = new DefaultBandwidthMeter();
            var adaptiveTrackSelectionFactory = new AdaptiveTrackSelection.Factory(defaultBandwidthMeter);
            var defaultTrackSelector          = new DefaultTrackSelector(adaptiveTrackSelectionFactory);

            player = ExoPlayerFactory.NewSimpleInstance(this, defaultTrackSelector);
        }
コード例 #6
0
        protected override void Dispose(bool disposing)
        {
            _player.Stop();
            _player.Release();

            trackSelector.Dispose();

            base.Dispose(disposing);
            _playerView   = null;
            trackSelector = null;
            _player       = null;
        }
コード例 #7
0
        public override void InitializePlayer()
        {
            var mainHandler = new Handler();
            var trackSelector = new DefaultTrackSelector(mainHandler);
            trackSelector.AddListener(this);
            var loadControl = new DefaultLoadControl();
            if (_mediaPlayer == null)
            {
                _mediaPlayer = ExoPlayerFactory.NewSimpleInstance(ApplicationContext, trackSelector, loadControl);
                _mediaPlayer.AddListener(this);
            }

            StatusChanged += (sender, args) => OnStatusChangedHandler(args);
        }
コード例 #8
0
 private void ReleasePlayer()
 {
     if (player != null)
     {
         debugViewHelper.Stop();
         debugViewHelper = null;
         shouldAutoPlay  = player.PlayWhenReady;
         UpdateResumePosition();
         player.Release();
         player               = null;
         trackSelector        = null;
         trackSelectionHelper = null;
         eventLogger          = null;
     }
 }
コード例 #9
0
ファイル: VideoController.cs プロジェクト: divitiae/playtube
        public void PlayVideo(string videoUrL, VideoObject videoObject, long resumePosition)
        {
            try
            {
                if (Player != null)
                {
                    SetStopvideo();

                    Player?.Release();
                    Player = null;

                    //GC Collecter
                    GC.Collect();
                }

                AdaptiveTrackSelection.Factory trackSelectionFactory = new AdaptiveTrackSelection.Factory();
                var trackSelector = new DefaultTrackSelector(trackSelectionFactory);
                var newParameters = new DefaultTrackSelector.ParametersBuilder()
                                    .SetMaxVideoSizeSd()
                                    .SetPreferredAudioLanguage("deu")
                                    .Build();
                trackSelector.SetParameters(newParameters);

                Player = ExoPlayerFactory.NewSimpleInstance(ActivityContext, trackSelector);
                FullWidthSetting();

                DefaultDataMediaFactory = new DefaultDataSourceFactory(ActivityContext, Util.GetUserAgent(ActivityContext, AppSettings.ApplicationName), BandwidthMeter);

                VideoSource = null;
                VideoSource = GetMediaSourceFromUrl(Uri.Parse(videoUrL), "normal");

                SimpleExoPlayerView.Player = Player;
                Player.Prepare(VideoSource);
                Player.AddListener(PlayerListener);
                Player.PlayWhenReady = true;
                Player.AddVideoListener(this);

                bool haveResumePosition = ResumeWindow != C.IndexUnset;
                if (haveResumePosition)
                {
                    Player.SeekTo(ResumeWindow, resumePosition);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
コード例 #10
0
        public override void InitializePlayer()
        {
            var mainHandler   = new Handler();
            var trackSelector = new DefaultTrackSelector(mainHandler);

            trackSelector.AddListener(this);
            var loadControl = new DefaultLoadControl();

            if (_mediaPlayer == null)
            {
                _mediaPlayer = ExoPlayerFactory.NewSimpleInstance(ApplicationContext, trackSelector, loadControl);
                _mediaPlayer.AddListener(this);
            }

            StatusChanged += (sender, args) => OnStatusChangedHandler(args);
        }
コード例 #11
0
        private void ReleasePlayer()
        {
            if (player != null)
            {
                UpdateTrackSelectorParameters();
                UpdateStartPosition();
                debugViewHelper.Stop();
                debugViewHelper = null;
                player.Release();
                player        = null;
                mediaSource   = null;
                trackSelector = null;

                //Todo: implement IAnalyticsListener
                eventLogger = null;
            }
            ReleaseMediaDrm();
        }
コード例 #12
0
ファイル: PRecyclerView.cs プロジェクト: projectsoca/onefete
        private void SetPlayer()
        {
            try
            {
                AdaptiveTrackSelection.Factory trackSelectionFactory = new AdaptiveTrackSelection.Factory();
                var trackSelector = new DefaultTrackSelector(trackSelectionFactory);
                trackSelector.SetParameters(new DefaultTrackSelector.ParametersBuilder().Build());

                VideoPlayer = ExoPlayerFactory.NewSimpleInstance(MainContext, trackSelector);

                DefaultDataSourceFac           = new DefaultDataSourceFactory(MainContext, Util.GetUserAgent(MainContext, AppSettings.ApplicationName), BandwidthMeter);
                VideoSurfaceView.UseController = true;
                VideoSurfaceView.Player        = VideoPlayer;
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
コード例 #13
0
        private void SetPlayer()
        {
            try
            {
                var BandwidthMeter = DefaultBandwidthMeter.GetSingletonInstance(this);

                DefaultTrackSelector trackSelector = new DefaultTrackSelector(this);
                trackSelector.SetParameters(new DefaultTrackSelector.ParametersBuilder(this));

                VideoPlayer = new SimpleExoPlayer.Builder(this).SetTrackSelector(trackSelector).Build();

                DefaultDataSourceFac           = new DefaultDataSourceFactory(this, Util.GetUserAgent(this, AppSettings.ApplicationName), BandwidthMeter);
                VideoSurfaceView.UseController = true;
                VideoSurfaceView.Player        = VideoPlayer;
            }
            catch (Exception e)
            {
                Methods.DisplayReportResultTrack(e);
            }
        }
コード例 #14
0
        private PlayerManager(IQueuePositionListener queuePositionListener, PlayerView localPlayerView, PlayerControlView castControlView, Context context, CastContext castContext)
        {
            this.queuePositionListener = queuePositionListener;
            this.localPlayerView       = localPlayerView;
            this.castControlView       = castControlView;
            mediaQueue               = new List <DemoUtil.Sample>();
            currentItemIndex         = C.IndexUnset;
            concatenatingMediaSource = new ConcatenatingMediaSource();

            DefaultTrackSelector trackSelector    = new DefaultTrackSelector(BANDWIDTH_METER);
            IRenderersFactory    renderersFactory = new DefaultRenderersFactory(context);

            exoPlayer = ExoPlayerFactory.NewSimpleInstance(renderersFactory, trackSelector);
            exoPlayer.AddListener(this);
            localPlayerView.Player = exoPlayer;

            castPlayer = new CastPlayer(castContext);
            castPlayer.AddListener(this);
            castPlayer.SetSessionAvailabilityListener(this);
            castControlView.Player = castPlayer;
        }
コード例 #15
0
 private void InitializePlayer()
 {
     try
     {
         if (Constant.Player == null)
         {
             AdaptiveTrackSelection.Factory trackSelectionFactory = new AdaptiveTrackSelection.Factory();
             var trackSelector = new DefaultTrackSelector(trackSelectionFactory);
             Constant.Player = ExoPlayerFactory.NewSimpleInstance(Constant.Context, trackSelector);
             PlayerListener  = new PlayerEvents(this);
             Constant.Player.AddListener(PlayerListener);
             Constant.Player.SetAudioAttributes(new AudioAttributes.Builder().SetUsage(C.UsageMedia).SetContentType(C.ContentTypeMusic).Build(), true);
             Constant.Player.SeekParameters  = SeekParameters.Default;
             Constant.Player.AudioAttributes = AudioAttributes.Default;
         }
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
     }
 }
コード例 #16
0
        public void Init(Context context, Com.Google.Android.Exoplayer2.UI.PlayerView playerView)
        {
            // Create a default track selector.
            var bandwidthMeter             = new DefaultBandwidthMeter();
            var videoTrackSelectionFactory =
                new AdaptiveTrackSelection.Factory(bandwidthMeter);
            TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory);

            // Create a player instance.
            player = ExoPlayerFactory.NewSimpleInstance(context, trackSelector);

            // Bind the player to the view.
            playerView.Player = (player);

            // This is the MediaSource representing the content media (i.e. not the ad).
            var contentUrl = url;            //context.GetString (Resource.String.test_content_url);

            HlsMediaSource.Factory hlsfac = new HlsMediaSource.Factory(mediaDataSourceFactory);
            //var hlsMediaSource = hlsfac.CreateMediaSource (Uri.Parse(contentUrl));
            var hlsMediaSource = new HlsMediaSource(Uri.Parse(contentUrl), mediaDataSourceFactory, null, null);
            //var contentMediaSource =
            //BuildMediaSource (Uri.Parse (contentUrl),"");

            // Compose the content media source into a new AdsMediaSource with both ads and content.
            var mediaSourceWithAds = hlsMediaSource;

            //        new AdsMediaSource(
            //                hlsMediaSource,
            //            /* adMediaSourceFactory= */ this,
            //             adsLoader,
            //            playerView.getOverlayFrameLayout(),
            //            /* eventHandler= */ null,
            //            /* eventListener= */ null);

            // Prepare the player with the source.
            player.SeekTo(contentPosition);
            player.Prepare(hlsMediaSource);
            player.PlayWhenReady = (true);
        }
コード例 #17
0
ファイル: AudioService.cs プロジェクト: DumbassHD/GlobalFM
        public void PlayAudio(string url)
        {
            if (isPlaying)
            {
                Stop();
            }
            current_url = url;
            var context   = Android.App.Application.Context;
            var mediaUri  = Android.Net.Uri.Parse(url);
            var userAgent = Util.GetUserAgent(context, "GlobalFM");
            var defaultHttpDataSourceFactory  = new DefaultHttpDataSourceFactory(userAgent);
            var defaultDataSourceFactory      = new DefaultDataSourceFactory(context, null, defaultHttpDataSourceFactory);
            var extractorMediaSource          = new ExtractorMediaSource(mediaUri, defaultDataSourceFactory, new DefaultExtractorsFactory(), null, null);
            var defaultBandwidthMeter         = new DefaultBandwidthMeter();
            var adaptiveTrackSelectionFactory = new AdaptiveTrackSelection.Factory(defaultBandwidthMeter);
            var defaultTrackSelector          = new DefaultTrackSelector(adaptiveTrackSelectionFactory);

            player = ExoPlayerFactory.NewSimpleInstance(context, defaultTrackSelector);
            player.Prepare(extractorMediaSource);
            player.PlayWhenReady = true;
            isPlaying            = true;
        }
コード例 #18
0
        private void InitializePlayer()
        {
            trackSelector = new DefaultTrackSelector();
            trackSelector.SetParameters(new DefaultTrackSelector.ParametersBuilder()
                                        .SetRendererDisabled(C.TrackTypeVideo, true)
                                        .Build()
                                        );
            _player     = ExoPlayerFactory.NewSimpleInstance(Context, trackSelector);
            _playerView = new PlayerView(Context)
            {
                Player = _player
            };

            ((IVideoPlayerController)Element).Fullscreen = false;

            SetNativeControl(_playerView);
            SetBackgroundColor(Android.Graphics.Color.Black);

            _playerView.UseController = Element.AreTransportControlsEnabled;
            _player.PlayWhenReady     = Element.AutoPlay;
            INITIAL_HEIGHT            = (int)Element.HeightRequest;
        }
コード例 #19
0
        public override void InitializePlayer()
        {
            bool needNewPlayer = _mediaPlayer == null;

            if (needNewPlayer)
            {
                var adaptiveTrackSelectionFactory =
                    new AdaptiveTrackSelection.Factory(BANDWIDTH_METER);
                var trackSelector = new DefaultTrackSelector(adaptiveTrackSelectionFactory);
                var eventLogger   = new ExoPlayerEventLogger(trackSelector);

                var renderersFactory = new DefaultRenderersFactory(ApplicationContext);
                var loadControl      = new DefaultLoadControl();

                _mediaPlayer = ExoPlayerFactory.NewSimpleInstance(renderersFactory, trackSelector, loadControl);
                _mediaPlayer.AddListener(eventLogger);
                _mediaPlayer.AddListener(this);
                _mediaPlayer.SetAudioDebugListener(eventLogger);
                _mediaPlayer.SetMetadataOutput(eventLogger);
            }

            StatusChanged += (sender, args) => OnStatusChangedHandler(args);
        }
コード例 #20
0
        //private void txtHideComment_Click(object sender, EventArgs e)
        //{
        //    txtHideComment.Visibility = ViewStates.Gone;
        //    FragmentTransaction ftvideo = SupportFragmentManager.BeginTransaction();
        //    ftvideo.AddToBackStack(null);
        //    ftvideo.SetCustomAnimations(Resource.Animation.slide_up, Resource.Animation.slide_down);
        //    ftvideo.Hide(CommentsFragment).Commit();
        //}
        private void InitializePlayer()
        {
            try
            {
                AdaptiveTrackSelection.Factory trackSelectionFactory = new AdaptiveTrackSelection.Factory();
                var trackSelector = new DefaultTrackSelector(trackSelectionFactory);

                var newParameters = new DefaultTrackSelector.ParametersBuilder()
                                    .SetMaxVideoSizeSd()
                                    .Build();

                trackSelector.SetParameters(newParameters);

                //DefaultLoadControl.Builder builder = new DefaultLoadControl.Builder();

                //builder.SetBufferDurationsMs(DefaultLoadControl.DefaultMinBufferMs, 60000, DefaultLoadControl.DefaultBufferForPlaybackMs, DefaultLoadControl.DefaultBufferForPlaybackAfterRebufferMs);
                //DefaultLoadControl loadControl = builder.CreateDefaultLoadControl();
                //
                Player = ExoPlayerFactory.NewSimpleInstance(this, trackSelector);
            }
            catch (System.Exception)
            {
            }
        }
コード例 #21
0
        private void InitializePlayer()
        {
            try
            {
                if (selectedMedia.Status == 1)
                {
                    btnAcceptReject.Text               = "Reject";
                    btnAcceptReject.Background         = Resources.GetDrawable(Resource.Drawable.Shape_Radius_Btn);
                    btnAcceptReject.BackgroundTintList = Resources.GetColorStateList(Resource.Color.gnt_red);
                }
                else
                {
                    btnAcceptReject.Text               = "Accept";
                    btnAcceptReject.Background         = Resources.GetDrawable(Resource.Drawable.Shape_Radius_Btn);
                    btnAcceptReject.BackgroundTintList = Resources.GetColorStateList(Android.Resource.Color.HoloGreenLight);
                }
                AdaptiveTrackSelection.Factory trackSelectionFactory = new AdaptiveTrackSelection.Factory();
                var trackSelector = new DefaultTrackSelector(trackSelectionFactory);

                var newParameters = new DefaultTrackSelector.ParametersBuilder()
                                    .SetMaxVideoSizeSd()
                                    .Build();

                trackSelector.SetParameters(newParameters);

                //DefaultLoadControl.Builder builder = new DefaultLoadControl.Builder();

                //builder.SetBufferDurationsMs(DefaultLoadControl.DefaultMinBufferMs, 60000, DefaultLoadControl.DefaultBufferForPlaybackMs, DefaultLoadControl.DefaultBufferForPlaybackAfterRebufferMs);
                //DefaultLoadControl loadControl = builder.CreateDefaultLoadControl();
                //
                Player = ExoPlayerFactory.NewSimpleInstance(this, trackSelector);
            }
            catch (System.Exception)
            {
            }
        }
コード例 #22
0
        public void PlayVideo(string videoUrL, GetMoviesObject.Movie videoObject)
        {
            try
            {
                if (videoObject != null)
                {
                    VideoData = videoObject;

                    VideoViewerActivity.GetInstance()?.TabVideosAbout?.LoadVideo_Data(videoObject);

                    TabbedMainActivity.GetInstance()?.SetOnWakeLock();

                    ReleaseVideo();

                    MFullScreenIcon.SetImageDrawable(ActivityContext.GetDrawable(Resource.Drawable.ic_action_ic_fullscreen_expand));

                    Uri videoUrl = Uri.Parse(!string.IsNullOrEmpty(videoUrL) ? videoUrL : VideoData.Source);

                    AdaptiveTrackSelection.Factory trackSelectionFactory = new AdaptiveTrackSelection.Factory();
                    var trackSelector = new DefaultTrackSelector(DefaultTrackSelector.Parameters.GetDefaults(ActivityContext), trackSelectionFactory);
                    trackSelector.SetParameters(new DefaultTrackSelector.ParametersBuilder(ActivityContext));

                    Player = new SimpleExoPlayer.Builder(ActivityContext).Build();

                    // Produces DataSource instances through which media data is loaded.
                    var defaultSource = GetMediaSourceFromUrl(videoUrl, videoUrl?.Path?.Split('.').Last(), "normal", IDrmSessionManager.DummyDrmSessionManager);

                    VideoSource = null !;

                    //Set Interactive Media Ads
                    if (PlayerSettings.ShowInteractiveMediaAds)
                    {
                        VideoSource = CreateMediaSourceWithAds(defaultSource, PlayerSettings.ImAdsUri);
                    }

                    if (SimpleExoPlayerView == null)
                    {
                        Initialize();
                    }

                    //Set Cache Media Load
                    if (PlayerSettings.EnableOfflineMode)
                    {
                        VideoSource = VideoSource == null?CreateCacheMediaSource(defaultSource, videoUrl) : CreateCacheMediaSource(VideoSource, videoUrl);

                        if (VideoSource != null)
                        {
                            SimpleExoPlayerView.Player = Player;
                            Player.Prepare(VideoSource);
                            //Player.AddListener(PlayerListener);
                            Player.PlayWhenReady = true;

                            bool haveResumePosition = ResumeWindow != C.IndexUnset;
                            if (haveResumePosition)
                            {
                                Player.SeekTo(ResumeWindow, ResumePosition);
                            }

                            return;
                        }
                    }

                    if (VideoSource == null)
                    {
                        if (!string.IsNullOrEmpty(videoUrL))
                        {
                            if (videoUrL.Contains("youtube") || videoUrL.Contains("Youtube") || videoUrL.Contains("youtu"))
                            {
                                //Task.Factory.StartNew(async () =>
                                //{
                                //    var newurl = await VideoInfoRetriever.GetEmbededVideo(VideoData.source);
                                //    videoSource = CreateDefaultMediaSource(Android.Net.Uri.Parse(newurl));
                                //});
                            }
                            else
                            {
                                VideoSource = GetMediaSourceFromUrl(Uri.Parse(videoUrL), videoUrL?.Split('.').Last(), "normal", IDrmSessionManager.DummyDrmSessionManager);

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

                                bool haveResumePosition = ResumeWindow != C.IndexUnset;
                                if (haveResumePosition)
                                {
                                    Player.SeekTo(ResumeWindow, ResumePosition);
                                }
                            }
                        }
                    }
                    else
                    {
                        SimpleExoPlayerView.Player = Player;
                        Player.Prepare(VideoSource);
                        //Player.AddListener(PlayerListener);
                        Player.PlayWhenReady = true;

                        bool haveResumePosition = ResumeWindow != C.IndexUnset;
                        if (haveResumePosition)
                        {
                            Player.SeekTo(ResumeWindow, ResumePosition);
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                Methods.DisplayReportResultTrack(exception);
            }
        }
コード例 #23
0
        public void PlayVideo(string videoUrL, Get_Movies_Object.Movie videoObject)
        {
            try
            {
                if (videoObject != null)
                {
                    Videodata = videoObject;

                    LoadVideo_Data(videoObject);

                    ReleaseVideo();

                    if (Settings.Allow_Offline_Download == false)
                    {
                        Download_icon.Visibility = ViewStates.Gone;
                    }

                    mFullScreenIcon.SetImageDrawable(ActivityContext.GetDrawable(Resource.Drawable.ic_action_ic_fullscreen_expand));

                    Android.Net.Uri videoURL;
                    if (!string.IsNullOrEmpty(videoUrL))
                    {
                        videoURL = Android.Net.Uri.Parse(videoUrL);
                    }
                    else
                    {
                        videoURL = Android.Net.Uri.Parse(Videodata.source);
                    }

                    mainHandler = new Handler();

                    AdaptiveTrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(BANDWIDTH_METER);
                    DefaultTrackSelector           trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory);

                    Player = ExoPlayerFactory.NewSimpleInstance(ActivityContext, trackSelector);
                    DefaultDatamediaFactory = new DefaultDataSourceFactory(ActivityContext, Util.GetUserAgent(ActivityContext, Settings.Application_Name), BANDWIDTH_METER);

                    // Produces DataSource instances through which media data is loaded.
                    ExtractorMediaSource DefaultSource = new ExtractorMediaSource(videoURL, DefaultDatamediaFactory, new DefaultExtractorsFactory(), mainHandler, eventLogger);

                    videoSource = null;

                    //Set Interactive Media Ads
                    if (Player_Settings.ShowInteractiveMediaAds)
                    {
                        videoSource = CreateAdsMediaSource(DefaultSource, Player_Settings.IMAdsUri);
                    }

                    if (simpleExoPlayerView == null)
                    {
                        Initialize();
                    }

                    //Set Cache Media Load
                    if (Player_Settings.EnableOfflineMode)
                    {
                        videoSource = videoSource == null?CreateCacheMediaSource(DefaultSource, videoURL) : CreateCacheMediaSource(videoSource, videoURL);

                        if (videoSource != null)
                        {
                            Download_icon.SetImageDrawable(ActivityContext.GetDrawable(Resource.Drawable.ic_checked_red));
                            Download_icon.Tag = "Downloaded";

                            simpleExoPlayerView.Player = Player;
                            Player.Prepare(videoSource);
                            Player.AddListener(PlayerLitsener);
                            Player.PlayWhenReady = true;

                            bool haveResumePosition = resumeWindow != C.IndexUnset;
                            if (haveResumePosition)
                            {
                                Player.SeekTo(resumeWindow, resumePosition);
                            }

                            return;
                        }
                    }

                    if (videoSource == null)
                    {
                        if (!string.IsNullOrEmpty(videoUrL))
                        {
                            if (videoUrL.Contains("youtube") || videoUrL.Contains("Youtube") || videoUrL.Contains("youtu"))
                            {
                                Task.Run(async() =>
                                {
                                    var newurl  = await VideoInfoRetriever.GetEmbededVideo(Videodata.source);
                                    videoSource = CreateDefaultMediaSource(Android.Net.Uri.Parse(newurl));
                                });
                            }
                            else
                            {
                                videoSource = CreateDefaultMediaSource(Android.Net.Uri.Parse(videoUrL));

                                simpleExoPlayerView.Player = Player;
                                Player.Prepare(videoSource);
                                Player.AddListener(PlayerLitsener);
                                Player.PlayWhenReady = true;

                                bool haveResumePosition = resumeWindow != C.IndexUnset;
                                if (haveResumePosition)
                                {
                                    Player.SeekTo(resumeWindow, resumePosition);
                                }
                            }
                        }
                    }
                    else
                    {
                        simpleExoPlayerView.Player = Player;
                        Player.Prepare(videoSource);
                        Player.AddListener(PlayerLitsener);
                        Player.PlayWhenReady = true;

                        bool haveResumePosition = resumeWindow != C.IndexUnset;
                        if (haveResumePosition)
                        {
                            Player.SeekTo(resumeWindow, resumePosition);
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                Crashes.TrackError(exception);
            }
        }
コード例 #24
0
        // Internal methods

        private void initializePlayer()
        {
            Intent intent        = Intent;
            bool   needNewPlayer = player == null;

            if (needNewPlayer)
            {
                var adaptiveTrackSelectionFactory =
                    new AdaptiveTrackSelection.Factory(BANDWIDTH_METER);
                trackSelector           = new DefaultTrackSelector(adaptiveTrackSelectionFactory);
                trackSelectionHelper    = new TrackSelectionHelper(trackSelector, adaptiveTrackSelectionFactory);
                lastSeenTrackGroupArray = null;
                eventLogger             = new EventLogger(trackSelector);

                var drmSchemeUuid = intent.HasExtra(DRM_SCHEME_UUID_EXTRA)
                                        ? UUID.FromString(intent.GetStringExtra(DRM_SCHEME_UUID_EXTRA)) : null;
                IDrmSessionManager drmSessionManager = null;
                if (drmSchemeUuid != null)
                {
                    var drmLicenseUrl             = intent.GetStringExtra(DRM_LICENSE_URL);
                    var keyRequestPropertiesArray = intent.GetStringArrayExtra(DRM_KEY_REQUEST_PROPERTIES);
                    int errorStringId             = Resource.String.error_drm_unknown;
                    if (Util.Util.SdkInt < 18)
                    {
                        errorStringId = Resource.String.error_drm_not_supported;
                    }
                    else
                    {
                        try
                        {
                            drmSessionManager = BuildDrmSessionManagerV18(drmSchemeUuid, drmLicenseUrl,
                                                                          keyRequestPropertiesArray);
                        }
                        catch (UnsupportedDrmException e)
                        {
                            errorStringId = e.Reason == UnsupportedDrmException.ReasonUnsupportedScheme
                                                                ? Resource.String.error_drm_unsupported_scheme : Resource.String.error_drm_unknown;
                        }
                    }
                    if (drmSessionManager == null)
                    {
                        ShowToast(errorStringId);
                        return;
                    }
                }

                var preferExtensionDecoders = intent.GetBooleanExtra(PREFER_EXTENSION_DECODERS, false);
                var extensionRendererMode   =
                    ((DemoApplication)Application).UseExtensionRenderers()
                                                ? (preferExtensionDecoders ? DefaultRenderersFactory.ExtensionRendererModePrefer
                                                : DefaultRenderersFactory.ExtensionRendererModeOn)
                                                : DefaultRenderersFactory.ExtensionRendererModeOff;
                var renderersFactory = new DefaultRenderersFactory(this,
                                                                   drmSessionManager, extensionRendererMode);

                player = ExoPlayerFactory.NewSimpleInstance(renderersFactory, trackSelector);
                player.AddListener(this);
                player.AddListener(eventLogger);
                player.SetAudioDebugListener(eventLogger);
                player.SetVideoDebugListener(eventLogger);
                player.SetMetadataOutput(eventLogger);

                simpleExoPlayerView.Player = player;
                player.PlayWhenReady       = shouldAutoPlay;
                debugViewHelper            = new DebugTextViewHelper(player, debugTextView);
                debugViewHelper.Start();
            }
            var action = intent.Action;

            Uri[]    uris;
            string[] extensions;
            if (ACTION_VIEW.Equals(action))
            {
                uris       = new Uri[] { intent.Data };
                extensions = new string[] { intent.GetStringExtra(EXTENSION_EXTRA) };
            }
            else if (ACTION_VIEW_LIST.Equals(action))
            {
                var uriStrings = intent.GetStringArrayExtra(URI_LIST_EXTRA);
                uris = new Uri[uriStrings.Length];
                for (int i = 0; i < uriStrings.Length; i++)
                {
                    uris[i] = Uri.Parse(uriStrings[i]);
                }
                extensions = intent.GetStringArrayExtra(EXTENSION_LIST_EXTRA);
                if (extensions == null)
                {
                    extensions = new string[uriStrings.Length];
                }
            }
            else
            {
                ShowToast(GetString(Resource.String.unexpected_intent_action, action));
                return;
            }
            if (Util.Util.MaybeRequestReadExternalStoragePermission(this, uris))
            {
                // The player will be reinitialized if the permission is granted.
                return;
            }
            var mediaSources = new IMediaSource[uris.Length];

            for (var i = 0; i < uris.Length; i++)
            {
                mediaSources[i] = BuildMediaSource(uris[i], extensions[i]);
            }
            var mediaSource = mediaSources.Length == 1 ? mediaSources[0]
                                : new ConcatenatingMediaSource(mediaSources);
            var adTagUriString = intent.GetStringExtra(AD_TAG_URI_EXTRA);

            if (adTagUriString != null)
            {
                Uri adTagUri = Uri.Parse(adTagUriString);
                if (!adTagUri.Equals(loadedAdTagUri))
                {
                    ReleaseAdsLoader();
                    loadedAdTagUri = adTagUri;
                }
                try
                {
                    mediaSource = CreateAdsMediaSource(mediaSource, Uri.Parse(adTagUriString));
                }
                catch (System.Exception)
                {
                    ShowToast(Resource.String.ima_not_loaded);
                }
            }
            else
            {
                ReleaseAdsLoader();
            }
            bool haveResumePosition = resumeWindow != C.IndexUnset;

            if (haveResumePosition)
            {
                player.SeekTo(resumeWindow, resumePosition);
            }
            player.Prepare(mediaSource, !haveResumePosition, false);
            inErrorState = false;
            UpdateButtonVisibilities();
        }
コード例 #25
0
        public virtual void Initialize()
        {
            if (Player != null)
            {
                return;
            }

            if (MediaSession == null)
            {
                throw new ArgumentNullException(nameof(MediaSession));
            }

            if (RequestHeaders?.Count > 0 && RequestHeaders.TryGetValue("User-Agent", out string userAgent))
            {
                UserAgent = userAgent;
            }
            else
            {
                UserAgent = Util.GetUserAgent(Context, "MediaManager");
            }

            HttpDataSourceFactory = new DefaultHttpDataSourceFactory(UserAgent);

            if (RequestHeaders?.Count > 0)
            {
                foreach (var item in RequestHeaders)
                {
                    HttpDataSourceFactory.DefaultRequestProperties.Set(item.Key, item.Value);
                }
            }

            DataSourceFactory      = new DefaultDataSourceFactory(Context, null, HttpDataSourceFactory);
            DashChunkSourceFactory = new DefaultDashChunkSource.Factory(DataSourceFactory);
            SsChunkSourceFactory   = new DefaultSsChunkSource.Factory(DataSourceFactory);

            BandwidthMeter        = new DefaultBandwidthMeter();
            TrackSelectionFactory = new AdaptiveTrackSelection.Factory(BandwidthMeter);
            TrackSelector         = new DefaultTrackSelector(TrackSelectionFactory);
            MediaSource           = new ConcatenatingMediaSource();

            Player = ExoPlayerFactory.NewSimpleInstance(Context, TrackSelector);

            var audioAttributes = new Com.Google.Android.Exoplayer2.Audio.AudioAttributes.Builder()
                                  .SetUsage(C.UsageMedia)
                                  .SetContentType(C.ContentTypeMusic)
                                  .Build();

            Player.AudioAttributes = audioAttributes;

            //TODO: Use this in 2.9.0
            //Player.SetAudioAttributes(audioAttributes, true);

            PlayerEventListener = new PlayerEventListener()
            {
                OnPlayerErrorImpl = (exception) =>
                {
                    MediaManager.OnMediaItemFailed(this, new MediaItemFailedEventArgs(MediaManager.MediaQueue.Current, exception, exception.Message));
                },
                OnTracksChangedImpl = (trackGroups, trackSelections) =>
                {
                    MediaManager.MediaQueue.CurrentIndex = Player.CurrentWindowIndex;
                    //TODO: Update metadata of item here
                }
            };
            Player.AddListener(PlayerEventListener);

            PlaybackController    = new PlaybackController();
            MediaSessionConnector = new MediaSessionConnector(MediaSession, PlaybackController);

            QueueNavigator = new QueueNavigator(MediaSession);
            MediaSessionConnector.SetQueueNavigator(QueueNavigator);

            QueueDataAdapter    = new QueueDataAdapter(MediaSource);
            MediaSourceFactory  = new QueueEditorMediaSourceFactory();
            TimelineQueueEditor = new TimelineQueueEditor(MediaSession.Controller, MediaSource, QueueDataAdapter, MediaSourceFactory);
            MediaSessionConnector.SetQueueEditor(TimelineQueueEditor);

            RatingCallback = new RatingCallback();
            MediaSessionConnector.SetRatingCallback(RatingCallback);

            PlaybackPreparer = new MediaSessionConnectorPlaybackPreparer(Player, MediaSource);
            MediaSessionConnector.SetPlayer(Player, PlaybackPreparer, null);
        }
コード例 #26
0
ファイル: VideoController.cs プロジェクト: divitiae/playtube
        public void PlayVideo(string videoUrL, VideoObject videoObject, RestrictedVideoFragment restrictedVideoPlayerFragment, Activity activity)
        {
            try
            {
                //RestrictedVideoPlayerFragment = restrictedVideoPlayerFragment;
                //ActivityFragment = activity;

                if (videoObject != null)
                {
                    VideoData = videoObject;
                    ReleaseVideo();

                    bool vidMonit = ListUtils.MySettingsList?.UsrVMon == "on" && VideoData.Monetization == "1" && VideoData.Owner.VideoMon == "1";

                    if (ListUtils.ArrayListPlay.Count > 0)
                    {
                        ListUtils.ArrayListPlay.Remove(VideoData);
                    }

                    var isPro = ListUtils.MyChannelList.FirstOrDefault()?.IsPro ?? "0";
                    if (!AppSettings.AllowOfflineDownload || AppSettings.AllowDownloadProUser && isPro == "0")
                    {
                        DownloadIcon.Visibility = ViewStates.Gone;
                    }

                    MFullScreenIcon.SetImageDrawable(ActivityContext.GetDrawable(Resource.Drawable.ic_action_ic_fullscreen_expand));

                    LoadingProgressBar.Visibility = ViewStates.Visible;

                    Uri url;
                    //Rent Or Sell
                    if (!string.IsNullOrEmpty(VideoData.SellVideo) && VideoData.SellVideo != "0" || !string.IsNullOrEmpty(VideoData.RentPrice) && VideoData.RentPrice != "0" && AppSettings.RentVideosSystem)
                    {
                        if (!string.IsNullOrEmpty(VideoData.Demo) && VideoData.IsPurchased == "0")
                        {
                            if (!VideoData.Demo.Contains(Client.WebsiteUrl))
                            {
                                VideoData.Demo = Client.WebsiteUrl + "/" + VideoData.Demo;
                            }

                            url = Uri.Parse(VideoData.Demo);
                            ShowRestrictedVideo = true;
                        }
                        else if (VideoData.IsPurchased != "0")
                        {
                            url = Uri.Parse(!string.IsNullOrEmpty(videoUrL) ? videoUrL : VideoData.VideoLocation);
                        }
                        else
                        {
                            if (!string.IsNullOrEmpty(VideoData.SellVideo) && VideoData.SellVideo != "0")
                            {
                                ShowRestrictedVideoFragment(restrictedVideoPlayerFragment, activity, "purchaseVideo");
                            }
                            else if (!string.IsNullOrEmpty(VideoData.RentPrice) && VideoData.RentPrice != "0" && AppSettings.RentVideosSystem)
                            {
                                ShowRestrictedVideoFragment(restrictedVideoPlayerFragment, activity, "RentVideo");
                            }
                            return;
                        }
                    }
                    else
                    {
                        url = Uri.Parse(!string.IsNullOrEmpty(videoUrL) ? videoUrL : VideoData.VideoLocation);
                    }

                    AdaptiveTrackSelection.Factory trackSelectionFactory = new AdaptiveTrackSelection.Factory();
                    var trackSelector = new DefaultTrackSelector(trackSelectionFactory);

                    var newParameters = new DefaultTrackSelector.ParametersBuilder()
                                        .SetMaxVideoSizeSd()
                                        .SetPreferredAudioLanguage("deu")
                                        .Build();

                    trackSelector.SetParameters(newParameters);

                    Player = ExoPlayerFactory.NewSimpleInstance(ActivityContext, trackSelector);

                    FullWidthSetting();

                    DefaultDataMediaFactory = new DefaultDataSourceFactory(ActivityContext, Util.GetUserAgent(ActivityContext, AppSettings.ApplicationName), BandwidthMeter);

                    VideoSource = null;

                    // Produces DataSource instances through which media data is loaded.
                    VideoSource = GetMediaSourceFromUrl(url, "normal");

                    if (SimpleExoPlayerView == null)
                    {
                        Initialize();
                    }

                    //Set Cache Media Load
                    if (PlayerSettings.EnableOfflineMode)
                    {
                        VideoSource = CreateCacheMediaSource(VideoSource, url);

                        if (VideoSource != null)
                        {
                            DownloadIcon.SetImageResource(Resource.Drawable.ic_checked_red);
                            DownloadIcon.Tag = "Downloaded";

                            RunVideoWithAds(VideoSource, vidMonit);
                            return;
                        }
                    }

                    //Set Interactive Media Ads
                    if (isPro == "0" && PlayerSettings.ShowInteractiveMediaAds && vidMonit)
                    {
                        VideoSource = CreateMediaSourceWithAds(VideoSource, PlayerSettings.ImAdsUri);
                    }

                    if (VideoSource == null)
                    {
                        VideoSource = GetMediaSourceFromUrl(url, "normal");

                        RunVideoWithAds(VideoSource, vidMonit);
                    }
                    else
                    {
                        RunVideoWithAds(VideoSource, vidMonit);
                    }
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
            }
        }
コード例 #27
0
        public void Start()
        {
            if (_player != null)
            {
                Stop();
            }

            _handler.Post(() =>
            {
                try
                {
                    var defaultBandwidthMeter         = new DefaultBandwidthMeter();
                    var adaptiveTrackSelectionFactory = new AdaptiveTrackSelection.Factory(defaultBandwidthMeter);
                    var defaultTrackSelector          = new DefaultTrackSelector(adaptiveTrackSelectionFactory);

                    _player = ExoPlayerFactory.NewSimpleInstance(_context, defaultTrackSelector);
                    _player.AddListener(this);
                    _player.PlayWhenReady = true;

                    if (Build.VERSION.SdkInt >= BuildVersionCodes.O)
                    {
                        var audioFocusRequest = new AudioFocusRequestClass.Builder(AudioFocus.Gain)
                                                .SetOnAudioFocusChangeListener(this)
                                                .SetAudioAttributes(new AudioAttributes.Builder()
                                                                    .SetUsage(AudioUsageKind.Media)
                                                                    .SetContentType(AudioContentType.Music)
                                                                    .Build())
                                                .Build();

                        if (_audioManager.RequestAudioFocus(audioFocusRequest) == AudioFocusRequest.Granted)
                        {
                            play();
                        }
                    }
                    else
                    {
                        #pragma warning disable CS0618 // Type or member is obsolete
                        if (_audioManager.RequestAudioFocus(this, Stream.Music, AudioFocus.Gain) == AudioFocusRequest.Granted)
                        {
                            play();
                        }
                        #pragma warning restore CS0618 // Type or member is obsolete
                    }
                }
                catch (Exception ex)
                {
                    //Log.Error(TAG, $"Could not start player: {ex.Message}");
                    //Log.Debug(TAG, ex.ToString());
                    Error?.Invoke(this, new RadioStationErrorEventArgs(ex));
                    IsPlaying = false;
                }
            });

            void play()
            {
                var mediaUri  = Android.Net.Uri.Parse(StreamUrl);
                var userAgent = Util.GetUserAgent(_context, "wzxv.app.radio.player");
                var defaultHttpDataSourceFactory = new DefaultHttpDataSourceFactory(userAgent);
                var defaultDataSourceFactory     = new DefaultDataSourceFactory(_context, null, defaultHttpDataSourceFactory);
                var mediaSourceFactory           = new ExtractorMediaSource.Factory(defaultDataSourceFactory);
                var mediaSource = mediaSourceFactory.CreateMediaSource(mediaUri);

                _player.Prepare(mediaSource);
                IsPlaying = true;
            }
        }
コード例 #28
0
        public void PlayVideo(string videoUrL)
        {
            try
            {
                if (!string.IsNullOrEmpty(videoUrL))
                {
                    VideoUrL = videoUrL;

                    ReleaseVideo();

                    FullScreenIcon.SetImageDrawable(ActivityContext.Context.GetDrawable(Resource.Drawable.ic_action_ic_fullscreen_expand));

                    LoadingProgressBar.Visibility = ViewStates.Visible;

                    Uri url = Uri.Parse(videoUrL);

                    AdaptiveTrackSelection.Factory trackSelectionFactory = new AdaptiveTrackSelection.Factory();
                    var trackSelector = new DefaultTrackSelector(trackSelectionFactory);
                    trackSelector.SetParameters(new DefaultTrackSelector.ParametersBuilder().Build());

                    Player = ExoPlayerFactory.NewSimpleInstance(ActivityContext.Context, trackSelector);

                    // Produces DataSource instances through which media data is loaded.
                    var defaultSource = GetMediaSourceFromUrl(url, "normal");

                    VideoSource = null;

                    if (SimpleExoPlayerView == null)
                    {
                        Initialize();
                    }

                    //Set Interactive Media Ads
                    if (PlayerSettings.ShowInteractiveMediaAds)
                    {
                        VideoSource = CreateMediaSourceWithAds(defaultSource, PlayerSettings.ImAdsUri);
                    }

                    //Set Cache Media Load
                    if (PlayerSettings.EnableOfflineMode)
                    {
                        VideoSource = VideoSource == null?CreateCacheMediaSource(defaultSource, url) : CreateCacheMediaSource(VideoSource, url);
                    }

                    if (VideoSource == null)
                    {
                        VideoSource = GetMediaSourceFromUrl(url, "normal");

                        SimpleExoPlayerView.Player = Player;
                        Player.Prepare(VideoSource);
                        Player.AddListener(PlayerListener);
                        Player.PlayWhenReady = true;
                    }
                    else
                    {
                        SimpleExoPlayerView.Player = Player;
                        Player.Prepare(VideoSource);
                        Player.AddListener(PlayerListener);
                        Player.PlayWhenReady = true;
                    }

                    bool haveResumePosition = ResumeWindow != C.IndexUnset;
                    if (haveResumePosition)
                    {
                        Player.SeekTo(ResumeWindow, ResumePosition);
                    }
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
            }
        }
コード例 #29
0
        // Internal methods

        private void InitializePlayer()
        {
            if (player == null)
            {
                Intent            intent = Intent;
                string            action = intent.Action;
                android.Net.Uri[] uris;
                string[]          extensions;

                if (ACTION_VIEW.Equals(action))
                {
                    uris       = new android.Net.Uri[] { intent.Data };
                    extensions = new string[] { intent.GetStringExtra(EXTENSION_EXTRA) };
                }
                else if (ACTION_VIEW_LIST.Equals(action))
                {
                    string[] uristrings = intent.GetStringArrayExtra(URI_LIST_EXTRA);
                    uris = new android.Net.Uri[uristrings.Length];
                    for (int i = 0; i < uristrings.Length; i++)
                    {
                        uris[i] = android.Net.Uri.Parse(uristrings[i]);
                    }
                    extensions = intent.GetStringArrayExtra(EXTENSION_LIST_EXTRA);
                    if (extensions == null)
                    {
                        extensions = new string[uristrings.Length];
                    }
                }
                else
                {
                    ShowToast(GetString(Resource.String.unexpected_intent_action, action));
                    Finish();
                    return;
                }
                if (Utils.MaybeRequestReadExternalStoragePermission(this, uris))
                {
                    // The player will be reinitialized if the permission is granted.
                    return;
                }

                DefaultDrmSessionManager drmSessionManager = null;
                if (intent.HasExtra(DRM_SCHEME_EXTRA) || intent.HasExtra(DRM_SCHEME_UUID_EXTRA))
                {
                    string   drmLicenseUrl             = intent.GetStringExtra(DRM_LICENSE_URL_EXTRA);
                    string[] keyRequestPropertiesArray =
                        intent.GetStringArrayExtra(DRM_KEY_REQUEST_PROPERTIES_EXTRA);
                    bool multiSession  = intent.GetBooleanExtra(DRM_MULTI_SESSION_EXTRA, false);
                    int  errorstringId = Resource.String.error_drm_unknown;
                    if (Utils.SdkInt < 18)
                    {
                        errorstringId = Resource.String.error_drm_not_supported;
                    }
                    else
                    {
                        try
                        {
                            string drmSchemeExtra = intent.HasExtra(DRM_SCHEME_EXTRA) ? DRM_SCHEME_EXTRA
                                : DRM_SCHEME_UUID_EXTRA;
                            UUID drmSchemeUuid = Utils.GetDrmUuid(intent.GetStringExtra(drmSchemeExtra));
                            if (drmSchemeUuid == null)
                            {
                                errorstringId = Resource.String.error_drm_unsupported_scheme;
                            }
                            else
                            {
                                drmSessionManager =
                                    BuildDrmSessionManagerV18(
                                        drmSchemeUuid, drmLicenseUrl, keyRequestPropertiesArray, multiSession);
                            }
                        }
                        catch (UnsupportedDrmException e)
                        {
                            errorstringId = e.Reason == UnsupportedDrmException.ReasonUnsupportedScheme
                                ? Resource.String.error_drm_unsupported_scheme : Resource.String.error_drm_unknown;
                        }
                    }
                    if (drmSessionManager == null)
                    {
                        ShowToast(errorstringId);
                        Finish();
                        return;
                    }
                }

                ITrackSelectionFactory trackSelectionFactory;
                string abrAlgorithm = intent.GetStringExtra(ABR_ALGORITHM_EXTRA);
                if (abrAlgorithm == null || ABR_ALGORITHM_DEFAULT.Equals(abrAlgorithm))
                {
                    trackSelectionFactory = new AdaptiveTrackSelection.Factory(BANDWIDTH_METER);
                }
                else if (ABR_ALGORITHM_RANDOM.Equals(abrAlgorithm))
                {
                    trackSelectionFactory = new RandomTrackSelection.Factory();
                }
                else
                {
                    ShowToast(Resource.String.error_unrecognized_abr_algorithm);
                    Finish();
                    return;
                }

                bool preferExtensionDecoders =
                    intent.GetBooleanExtra(PREFER_EXTENSION_DECODERS_EXTRA, false);
                int extensionRendererMode =
                    ((DemoApplication)Application).UseExtensionRenderers()
                        ? (preferExtensionDecoders ? DefaultRenderersFactory.ExtensionRendererModePrefer
                        : DefaultRenderersFactory.ExtensionRendererModeOn)
                        : DefaultRenderersFactory.ExtensionRendererModeOff;
                DefaultRenderersFactory renderersFactory =
                    new DefaultRenderersFactory(this, extensionRendererMode);

                trackSelector = new DefaultTrackSelector(trackSelectionFactory);
                trackSelector.SetParameters(trackSelectorParameters);
                lastSeenTrackGroupArray = null;

                player = ExoPlayerFactory.NewSimpleInstance(renderersFactory, trackSelector, drmSessionManager);

                eventLogger = new EventLogger(trackSelector);

                player.AddListener(new PlayerEventListener(this));
                player.PlayWhenReady = startAutoPlay;

                player.AddListener(eventLogger);

                // Cannot implement the AnalyticsListener because the binding doesn't work.

                //Todo: implement IAnalyticsListener
                //player.AddAnalyticsListener(eventLogger);

                player.AddAudioDebugListener(eventLogger);
                player.AddVideoDebugListener(eventLogger);

                player.AddMetadataOutput(eventLogger);
                //end Todo

                playerView.Player = player;
                playerView.SetPlaybackPreparer(this);
                debugViewHelper = new DebugTextViewHelper(player, debugTextView);
                debugViewHelper.Start();

                IMediaSource[] mediaSources = new IMediaSource[uris.Length];
                for (int i = 0; i < uris.Length; i++)
                {
                    mediaSources[i] = BuildMediaSource(uris[i], extensions[i]);
                }
                mediaSource =
                    mediaSources.Length == 1 ? mediaSources[0] : new ConcatenatingMediaSource(mediaSources);
                string adTagUristring = intent.GetStringExtra(AD_TAG_URI_EXTRA);
                if (adTagUristring != null)
                {
                    android.Net.Uri adTagUri = android.Net.Uri.Parse(adTagUristring);
                    if (!adTagUri.Equals(loadedAdTagUri))
                    {
                        ReleaseAdsLoader();
                        loadedAdTagUri = adTagUri;
                    }
                    IMediaSource adsMediaSource = CreateAdsMediaSource(mediaSource, android.Net.Uri.Parse(adTagUristring));
                    if (adsMediaSource != null)
                    {
                        mediaSource = adsMediaSource;
                    }
                    else
                    {
                        ShowToast(Resource.String.ima_not_loaded);
                    }
                }
                else
                {
                    ReleaseAdsLoader();
                }
            }
            bool haveStartPosition = startWindow != C.IndexUnset;

            if (haveStartPosition)
            {
                player.SeekTo(startWindow, startPosition);
            }
            player.Prepare(mediaSource, !haveStartPosition, false);
            UpdateButtonVisibilities();
        }