title: Quality selector for ExoPlayer 2
body: <p>I am currently developing a live and movie player application. I chose <strong>ExoPlayer version 2</strong> to play the movie and I do not know much about it. I want to let the user choose the <strong>quality of a movie</strong> on the player screen, for example, 720p or 1080p or etc.
  But I do not know how to get a list of existing qualities and show them to the user.
  and the below code is my implementation of SimpleExoPlayer :</p>
  
  <pre><code>private void initPlayer(String path){
      Handler handler = new Handler();
      // 1. Create a default TrackSelector
      BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
      TrackSelection.Factory videoTrackSelectionFactory =
              new AdaptiveVideoTrackSelection.Factory(bandwidthMeter);
      TrackSelector trackSelector =
              new DefaultTrackSelector(videoTrackSelectionFactory);
  
      // 2. Create a default LoadControl
      LoadControl loadControl = new DefaultLoadControl();
      // 3. Create the player
      player = ExoPlayerFactory.newSimpleInstance(this, trackSelector, loadControl);
  
      SimpleExoPlayerView playerView = (SimpleExoPlayerView) findViewById(R.id.player_view);
      playerView.setPlayer(player);
      playerView.setKeepScreenOn(true);
      // Produces DataSource instances through which media data is loaded.
      DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(this, Util.getUserAgent(this, "ExoPlayer"));
  
      // This is the MediaSource representing the media to be played.
      MediaSource videoSource = new HlsMediaSource(Uri.parse(path),
              dataSourceFactory,handler, null);
      // Prepare the player with the source.
      player.addListener(this);
      player.prepare(videoSource);
      playerView.requestFocus();
      player.setPlayWhenReady(true); // to play video when ready. Use false to pause a video
  }
  
  // ExoPlayer Listener Methods :
  @Override
  public void onTimelineChanged(Timeline timeline, Object manifest) {
  
  }
  
  @Override
  public void onTracksChanged(TrackGroupArray trackGroups, TrackSelectionArray trackSelections) {
  
  }
  
  @Override
  public void onLoadingChanged(boolean isLoading) {
  
  }
  
  @Override
  public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
      switch (playbackState) {
          case ExoPlayer.STATE_BUFFERING:
              //You can use progress dialog to show user that video is preparing or buffering so please wait
              progressBar.setVisibility(View.VISIBLE);
              break;
          case ExoPlayer.STATE_IDLE:
              //idle state
              break;
          case ExoPlayer.STATE_READY:
              // dismiss your dialog here because our video is ready to play now
              progressBar.setVisibility(GONE);
              //Toast.makeText(getApplicationContext(),String.valueOf(player.getCurrentTrackSelections().get(0).getSelectedFormat().bitrate),Toast.LENGTH_SHORT).show();
              break;
          case ExoPlayer.STATE_ENDED:
              // do your processing after ending of video
              break;
      }
  }
  
  @Override
  public void onPlayerError(ExoPlaybackException error) {
      // show user that something went wrong. it can be a dialog
  }
  
  @Override
  public void onPositionDiscontinuity() {
  
  }
  </code></pre>
  
  <p>please help to solve this issue.
  thanks a lot.</p>