// AudioCapabilitiesReceiver.Listener methods
 @Override
 public void onAudioCapabilitiesChanged(AudioCapabilities audioCapabilities) {
   boolean audioCapabilitiesChanged = !audioCapabilities.equals(this.audioCapabilities);
   if (player == null || audioCapabilitiesChanged) {
     this.audioCapabilities = audioCapabilities;
   } else if (player != null) {
     player.setBackgrounded(false);
   }
 }
  @Override
  public void buildRenderers(OkPlayer player) {

    Allocator allocator = new DefaultAllocator(BUFFER_SEGMENT_SIZE);
    DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(player.getMainHandler(), null);

    DataSource dataSource = new DefaultUriDataSource(context, bandwidthMeter, userAgent);
    ExtractorSampleSource sampleSource =
        new ExtractorSampleSource(
            uri, dataSource, allocator, BUFFER_SEGMENT_COUNT * BUFFER_SEGMENT_SIZE);

    //        Uri uri = Uri.parse(MediaUtil.getUriWithProtocol(this.uri.toString()));
    //        ExtractorSampleSource sampleSource = new ExtractorSampleSource(uri, dataSource,
    // allocator,
    //                BUFFER_SEGMENT_COUNT * BUFFER_SEGMENT_SIZE, new Mp4Extractor());

    MediaCodecVideoTrackRenderer videoRenderer =
        new MediaCodecVideoTrackRenderer(
            context,
            sampleSource,
            MediaCodec.VIDEO_SCALING_MODE_SCALE_TO_FIT,
            5000,
            player.getMainHandler(),
            player,
            50);
    MediaCodecAudioTrackRenderer audioRenderer =
        new MediaCodecAudioTrackRenderer(
            sampleSource,
            null,
            true,
            player.getMainHandler(),
            player,
            AudioCapabilities.getCapabilities(context));
    //        TrackRenderer textRenderer = new TextTrackRenderer(sampleSource, player,
    //                player.getMainHandler().getLooper());

    // Invoke the callback.
    TrackRenderer[] renderers = new TrackRenderer[OkPlayer.RENDERER_COUNT];
    renderers[OkPlayer.TYPE_VIDEO] = videoRenderer;
    renderers[OkPlayer.TYPE_AUDIO] = audioRenderer;
    //        renderers[OkPlayer.TYPE_TEXT] = textRenderer;
    player.onRenderers(renderers, bandwidthMeter);
  }
    @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);
    }
 @Override
 public void onAudioCapabilitiesChanged(AudioCapabilities audioCapabilities) {
   if (!audioCapabilities.equals(this.audioCapabilities)) {
     this.audioCapabilities = audioCapabilities;
   }
 }