public MvxVideoPlayer(IRendererBuilder rendererBuilder)
 {
     _rendererBuilder = rendererBuilder;
     _player          = ExoPlayerFactory.NewInstance(RendererCount, 1000, 5000);
     _player.AddListener(this);
     _playerControl             = new PlayerControl(_player);
     _mainHandler               = new Handler();
     _listeners                 = new List <IListener>();
     _lastReportedPlaybackState = StateIdle;
     _rendererBuildingState     = RendererBuildingStateIdle;
     // Disable text initially.
     _player.SetSelectedTrack(TypeText, TrackDisabled);
 }
 public MvxVideoPlayer(IRendererBuilder rendererBuilder)
 {
     _rendererBuilder = rendererBuilder;
     _player = ExoPlayerFactory.NewInstance(RendererCount, 1000, 5000);
     _player.AddListener(this);
     _playerControl = new PlayerControl(_player);
     _mainHandler = new Handler();
     _listeners = new List<IListener>();
     _lastReportedPlaybackState = StateIdle;
     _rendererBuildingState = RendererBuildingStateIdle;
     // Disable text initially.
     _player.SetSelectedTrack(TypeText, TrackDisabled);
 }
        private void IntializePlayer()
        {
            Player = ExoPlayerFactory.NewInstance(1);

            //Tell our player to sream music
            //ExoPlayer.SetAudioStreamType(Stream.Music);

            //Wake mode will be partial to keep the CPU still running under lock screen
            //ExoPlayer.SetWakeMode(ApplicationContext, WakeLockFlags.Partial);

            //When we have prepared the song start playback

            /*ExoPlayer.Prepared += (sender, args) => {
             *  if (remoteControlClient != null)
             *  {
             *      remoteControlClient.SetPlaybackState(RemoteControlPlayState.Playing);
             *  }
             *  if (prepared != null)
             *  {
             *      prepared(this, 0);
             *  }
             *  UpdateMetadata();
             *  starting = false;
             *  Player.Start();
             * };*/
            //TODO EXOPLAYER

            Task.Run(
                async() =>
            {
                while (true)
                {
                    try
                    {
                        if ((posChanged != null) && (Player != null))
                        {
                            if (Player.CurrentPosition > 0 && Player.Duration > 0)
                            {
                                posChanged(this, Player.CurrentPosition);
                            }
                        }
                        if ((percentChanged != null) && (Player != null))
                        {
                            if (Player.CurrentPosition > 0 && Player.Duration > 0)
                            {
                                int percent = (int)(Player.CurrentPosition * 100 / Player.Duration);
                                percentChanged(this, percent);
                            }
                        }
                        await Task.Delay(100);
                    }
                    catch
                    {
                        // ignored
                    }
                }
            });

            Player.AddListener(this);
            //When we have reached the end of the song stop ourselves, however you could signal next track here.

            /*
             * Player.Error += async (sender, args) =>
             * {
             *  Player.Reset();
             *  await Task.Delay(500);
             *  if (Player.IsPlaying)
             *  {
             *      return;
             *  }
             *  if (errorCounter <3)
             *  {
             *      errorCounter++;
             *      this.Play();
             *  }
             *  else
             *  {
             *      errorCounter = 0;
             *      if (remoteControlClient != null)
             *          remoteControlClient.SetPlaybackState(RemoteControlPlayState.Error);
             *      //playback error
             *      Console.WriteLine("Error in playback resetting: " + args.What);
             *      Stop();//this will clean up and reset properly.
             *      Next();
             *  }
             * };
             */
        }