@Override
    public void onSingleManifestError(IOException exception) {
      if (canceled) {
        return;
      }

      player.onRenderersError(exception);
    }
    @Override
    public void onSingleManifest(SmoothStreamingManifest manifest) {
      if (canceled) {
        return;
      }

      Handler mainHandler = player.getMainHandler();
      LoadControl loadControl = new DefaultLoadControl(new DefaultAllocator(BUFFER_SEGMENT_SIZE));
      DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(mainHandler, player);

      // Check drm support if necessary.
      DrmSessionManager drmSessionManager = null;
      if (manifest.protectionElement != null) {
        if (Util.SDK_INT < 18) {
          player.onRenderersError(
              new UnsupportedDrmException(UnsupportedDrmException.REASON_UNSUPPORTED_SCHEME));
          return;
        }
        try {
          drmSessionManager =
              new StreamingDrmSessionManager(
                  manifest.protectionElement.uuid,
                  player.getPlaybackLooper(),
                  drmCallback,
                  null,
                  player.getMainHandler(),
                  player);
        } catch (UnsupportedDrmException e) {
          player.onRenderersError(e);
          return;
        }
      }

      // Build the video renderer.
      DataSource videoDataSource = new DefaultUriDataSource(context, bandwidthMeter, userAgent);
      ChunkSource videoChunkSource =
          new SmoothStreamingChunkSource(
              manifestFetcher,
              new DefaultSmoothStreamingTrackSelector(context, StreamElement.TYPE_VIDEO),
              videoDataSource,
              new AdaptiveEvaluator(bandwidthMeter),
              LIVE_EDGE_LATENCY_MS);
      ChunkSampleSource videoSampleSource =
          new ChunkSampleSource(
              videoChunkSource,
              loadControl,
              VIDEO_BUFFER_SEGMENTS * BUFFER_SEGMENT_SIZE,
              mainHandler,
              player,
              DemoPlayer.TYPE_VIDEO);
      TrackRenderer videoRenderer =
          new MediaCodecVideoTrackRenderer(
              context,
              videoSampleSource,
              MediaCodec.VIDEO_SCALING_MODE_SCALE_TO_FIT,
              5000,
              drmSessionManager,
              true,
              mainHandler,
              player,
              50);

      // Build the audio renderer.
      DataSource audioDataSource = new DefaultUriDataSource(context, bandwidthMeter, userAgent);
      ChunkSource audioChunkSource =
          new SmoothStreamingChunkSource(
              manifestFetcher,
              new DefaultSmoothStreamingTrackSelector(context, StreamElement.TYPE_AUDIO),
              audioDataSource,
              null,
              LIVE_EDGE_LATENCY_MS);
      ChunkSampleSource audioSampleSource =
          new ChunkSampleSource(
              audioChunkSource,
              loadControl,
              AUDIO_BUFFER_SEGMENTS * BUFFER_SEGMENT_SIZE,
              mainHandler,
              player,
              DemoPlayer.TYPE_AUDIO);
      TrackRenderer audioRenderer =
          new MediaCodecAudioTrackRenderer(
              audioSampleSource,
              drmSessionManager,
              true,
              mainHandler,
              player,
              AudioCapabilities.getCapabilities(context));

      // Build the text renderer.
      DataSource textDataSource = new DefaultUriDataSource(context, bandwidthMeter, userAgent);
      ChunkSource textChunkSource =
          new SmoothStreamingChunkSource(
              manifestFetcher,
              new DefaultSmoothStreamingTrackSelector(context, StreamElement.TYPE_TEXT),
              textDataSource,
              null,
              LIVE_EDGE_LATENCY_MS);
      ChunkSampleSource textSampleSource =
          new ChunkSampleSource(
              textChunkSource,
              loadControl,
              TEXT_BUFFER_SEGMENTS * BUFFER_SEGMENT_SIZE,
              mainHandler,
              player,
              DemoPlayer.TYPE_TEXT);
      TrackRenderer textRenderer =
          new TextTrackRenderer(textSampleSource, player, mainHandler.getLooper());

      // Invoke the callback.
      TrackRenderer[] renderers = new TrackRenderer[DemoPlayer.RENDERER_COUNT];
      renderers[DemoPlayer.TYPE_VIDEO] = videoRenderer;
      renderers[DemoPlayer.TYPE_AUDIO] = audioRenderer;
      renderers[DemoPlayer.TYPE_TEXT] = textRenderer;
      player.onRenderers(renderers, bandwidthMeter);
    }