@Override
  public void onManifest(String contentId, MediaPresentationDescription manifest) {
    Handler mainHandler = player.getMainHandler();
    LoadControl loadControl = new DefaultLoadControl(new BufferPool(BUFFER_SEGMENT_SIZE));
    DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(mainHandler, player);
    // Obtain Representations for playback.
    int maxDecodableFrameSize = MediaCodecUtil.maxH264DecodableFrameSize();
    ArrayList<Representation> audioRepresentationsList = new ArrayList<Representation>();
    ArrayList<Representation> videoRepresentationsList = new ArrayList<Representation>();
    Period period = manifest.periods.get(0);
    boolean hasContentProtection = false;
    for (int i = 0; i < period.adaptationSets.size(); i++) {
      AdaptationSet adaptationSet = period.adaptationSets.get(i);
      hasContentProtection |= adaptationSet.hasContentProtection();
      int adaptationSetType = adaptationSet.type;
      for (int j = 0; j < adaptationSet.representations.size(); j++) {
        Representation representation = adaptationSet.representations.get(j);
        if (adaptationSetType == AdaptationSet.TYPE_AUDIO) {
          audioRepresentationsList.add(representation);
        } else if (adaptationSetType == AdaptationSet.TYPE_VIDEO) {
          Format format = representation.format;
          if (format.width * format.height <= maxDecodableFrameSize) {
            videoRepresentationsList.add(representation);
          } else {
            // The device isn't capable of playing this stream.
          }
        }
      }
    }
    Representation[] videoRepresentations = new Representation[videoRepresentationsList.size()];
    videoRepresentationsList.toArray(videoRepresentations);
    // Check drm support if necessary.
    DrmSessionManager drmSessionManager = null;
    if (hasContentProtection) {
      if (Util.SDK_INT < 18) {
        callback.onRenderersError(new UnsupportedOperationException(
            "Protected content not supported on API level " + Util.SDK_INT));
        return;
      }
      try {
        Pair<DrmSessionManager, Boolean> drmSessionManagerData =
            V18Compat.getDrmSessionManagerData(player, drmCallback);
        drmSessionManager = drmSessionManagerData.first;
        if (!drmSessionManagerData.second) {
          // HD streams require L1 security.
          videoRepresentations = getSdRepresentations(videoRepresentations);
        }
      } catch (Exception e) {
        callback.onRenderersError(e);
        return;
      }
    }
    // Build the video renderer.
    DataSource videoDataSource = new HttpDataSource(userAgent, null, bandwidthMeter);
    ChunkSource videoChunkSource;
    String mimeType = videoRepresentations[0].format.mimeType;
    if (mimeType.equals(MimeTypes.VIDEO_MP4)) {
      videoChunkSource = new DashMp4ChunkSource(videoDataSource,
          new AdaptiveEvaluator(bandwidthMeter), videoRepresentations);
    } else if (mimeType.equals(MimeTypes.VIDEO_WEBM)) {
      // TODO: Figure out how to query supported vpX resolutions. For now, restrict to standard
      // definition streams.
      videoRepresentations = getSdRepresentations(videoRepresentations);
      videoChunkSource = new DashWebmChunkSource(videoDataSource,
          new AdaptiveEvaluator(bandwidthMeter), videoRepresentations);
    } else {
      throw new IllegalStateException("Unexpected mime type: " + mimeType);
    }
    ChunkSampleSource videoSampleSource = new ChunkSampleSource(videoChunkSource, loadControl,
        VIDEO_BUFFER_SEGMENTS * BUFFER_SEGMENT_SIZE, true, mainHandler, player,
        DemoPlayer.TYPE_VIDEO);
    MediaCodecVideoTrackRenderer videoRenderer = new MediaCodecVideoTrackRenderer(videoSampleSource,
        drmSessionManager, true, MediaCodec.VIDEO_SCALING_MODE_SCALE_TO_FIT, 5000,
        mainHandler, player, 50);
    // Build the audio renderer.
    final String[] audioTrackNames;
    final MultiTrackChunkSource audioChunkSource;
    final MediaCodecAudioTrackRenderer audioRenderer;
    if (audioRepresentationsList.isEmpty()) {
      audioTrackNames = null;
      audioChunkSource = null;
      audioRenderer = null;
    } else {
      DataSource audioDataSource = new HttpDataSource(userAgent, null, bandwidthMeter);
      audioTrackNames = new String[audioRepresentationsList.size()];
      ChunkSource[] audioChunkSources = new ChunkSource[audioRepresentationsList.size()];
      FormatEvaluator audioEvaluator = new FormatEvaluator.FixedEvaluator();
      for (int i = 0; i < audioRepresentationsList.size(); i++) {
        Representation representation = audioRepresentationsList.get(i);
        Format format = representation.format;
        audioTrackNames[i] = format.id + " (" + format.numChannels + "ch, " +
            format.audioSamplingRate + "Hz)";
        audioChunkSources[i] = new DashMp4ChunkSource(audioDataSource,
            audioEvaluator, representation);
      }
      audioChunkSource = new MultiTrackChunkSource(audioChunkSources);
      SampleSource audioSampleSource = new ChunkSampleSource(audioChunkSource, loadControl,
          AUDIO_BUFFER_SEGMENTS * BUFFER_SEGMENT_SIZE, true, mainHandler, player,
          DemoPlayer.TYPE_AUDIO);
      audioRenderer = new MediaCodecAudioTrackRenderer(audioSampleSource, drmSessionManager, true,
          mainHandler, player);
    }
    // Build the debug renderer.
    TrackRenderer debugRenderer = debugTextView != null
        ? new DebugTrackRenderer(debugTextView, videoRenderer, videoSampleSource) : null;
    // Invoke the callback.
    String[][] trackNames = new String[DemoPlayer.RENDERER_COUNT][];
    trackNames[DemoPlayer.TYPE_AUDIO] = audioTrackNames;
    MultiTrackChunkSource[] multiTrackChunkSources =
        new MultiTrackChunkSource[DemoPlayer.RENDERER_COUNT];
    multiTrackChunkSources[DemoPlayer.TYPE_AUDIO] = audioChunkSource;
    TrackRenderer[] renderers = new TrackRenderer[DemoPlayer.RENDERER_COUNT];
    renderers[DemoPlayer.TYPE_VIDEO] = videoRenderer;
    renderers[DemoPlayer.TYPE_AUDIO] = audioRenderer;
    renderers[DemoPlayer.TYPE_DEBUG] = debugRenderer;
    callback.onRenderers(trackNames, multiTrackChunkSources, renderers);
  }
@Override
  public void onManifest(String contentId, MediaPresentationDescription manifest) {
    Handler mainHandler = player.getMainHandler();
    LoadControl loadControl = new DefaultLoadControl(new BufferPool(BUFFER_SEGMENT_SIZE));
    DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(mainHandler, player);
   
    int maxDecodableFrameSize = MediaCodecUtil.maxH264DecodableFrameSize();
    ArrayList<Representation> audioRepresentationsList = new ArrayList<Representation>();
    ArrayList<Representation> videoRepresentationsList = new ArrayList<Representation>();
    Period period = manifest.periods.get(0);
    boolean hasContentProtection = false;
    for (int i = 0; i < period.adaptationSets.size(); i++) {
      AdaptationSet adaptationSet = period.adaptationSets.get(i);
      hasContentProtection |= adaptationSet.hasContentProtection();
      int adaptationSetType = adaptationSet.type;
      for (int j = 0; j < adaptationSet.representations.size(); j++) {
        Representation representation = adaptationSet.representations.get(j);
        if (adaptationSetType == AdaptationSet.TYPE_AUDIO) {
          audioRepresentationsList.add(representation);
        } else if (adaptationSetType == AdaptationSet.TYPE_VIDEO) {
          Format format = representation.format;
          if (format.width * format.height <= maxDecodableFrameSize) {
            videoRepresentationsList.add(representation);
          } else {
           
          }
        }
      }
    }
    Representation[] videoRepresentations = new Representation[videoRepresentationsList.size()];
    videoRepresentationsList.toArray(videoRepresentations);
   
    DrmSessionManager drmSessionManager = null;
    if (hasContentProtection) {
      if (Util.SDK_INT < 18) {
        callback.onRenderersError(new UnsupportedOperationException(
            "Protected content not supported on API level " + Util.SDK_INT));
        return;
      }
      try {
        Pair<DrmSessionManager, Boolean> drmSessionManagerData =
            V18Compat.getDrmSessionManagerData(player, drmCallback);
        drmSessionManager = drmSessionManagerData.first;
        if (!drmSessionManagerData.second) {
         
          videoRepresentations = getSdRepresentations(videoRepresentations);
        }
      } catch (Exception e) {
        callback.onRenderersError(e);
        return;
      }
    }
   
    DataSource videoDataSource = new HttpDataSource(userAgent, null, bandwidthMeter);
    ChunkSource videoChunkSource;
    String mimeType = videoRepresentations[0].format.mimeType;
    if (mimeType.equals(MimeTypes.VIDEO_MP4)) {
      videoChunkSource = new DashMp4ChunkSource(videoDataSource,
          new AdaptiveEvaluator(bandwidthMeter), videoRepresentations);
    } else if (mimeType.equals(MimeTypes.VIDEO_WEBM)) {
     
     
      videoRepresentations = getSdRepresentations(videoRepresentations);
      videoChunkSource = new DashWebmChunkSource(videoDataSource,
          new AdaptiveEvaluator(bandwidthMeter), videoRepresentations);
    } else {
      throw new IllegalStateException("Unexpected mime type: " + mimeType);
    }
    ChunkSampleSource videoSampleSource = new ChunkSampleSource(videoChunkSource, loadControl,
        VIDEO_BUFFER_SEGMENTS * BUFFER_SEGMENT_SIZE, true, mainHandler, player,
        DemoPlayer.TYPE_VIDEO);
    MediaCodecVideoTrackRenderer videoRenderer = new MediaCodecVideoTrackRenderer(videoSampleSource,
        drmSessionManager, true, MediaCodec.VIDEO_SCALING_MODE_SCALE_TO_FIT, 5000,
        mainHandler, player, 50);
   
    final String[] audioTrackNames;
    final MultiTrackChunkSource audioChunkSource;
    final MediaCodecAudioTrackRenderer audioRenderer;
    if (audioRepresentationsList.isEmpty()) {
      audioTrackNames = null;
      audioChunkSource = null;
      audioRenderer = null;
    } else {
      DataSource audioDataSource = new HttpDataSource(userAgent, null, bandwidthMeter);
      audioTrackNames = new String[audioRepresentationsList.size()];
      ChunkSource[] audioChunkSources = new ChunkSource[audioRepresentationsList.size()];
      FormatEvaluator audioEvaluator = new FormatEvaluator.FixedEvaluator();
      for (int i = 0; i < audioRepresentationsList.size(); i++) {
        Representation representation = audioRepresentationsList.get(i);
        Format format = representation.format;
        audioTrackNames[i] = format.id + " (" + format.numChannels + "ch, " +
            format.audioSamplingRate + "Hz)";
        audioChunkSources[i] = new DashMp4ChunkSource(audioDataSource,
            audioEvaluator, representation);
      }
      audioChunkSource = new MultiTrackChunkSource(audioChunkSources);
      SampleSource audioSampleSource = new ChunkSampleSource(audioChunkSource, loadControl,
          AUDIO_BUFFER_SEGMENTS * BUFFER_SEGMENT_SIZE, true, mainHandler, player,
          DemoPlayer.TYPE_AUDIO);
      audioRenderer = new MediaCodecAudioTrackRenderer(audioSampleSource, drmSessionManager, true,
          mainHandler, player);
    }
   
    TrackRenderer debugRenderer = debugTextView != null
        ? new DebugTrackRenderer(debugTextView, videoRenderer, videoSampleSource) : null;
   
    String[][] trackNames = new String[DemoPlayer.RENDERER_COUNT][];
    trackNames[DemoPlayer.TYPE_AUDIO] = audioTrackNames;
    MultiTrackChunkSource[] multiTrackChunkSources =
        new MultiTrackChunkSource[DemoPlayer.RENDERER_COUNT];
    multiTrackChunkSources[DemoPlayer.TYPE_AUDIO] = audioChunkSource;
    TrackRenderer[] renderers = new TrackRenderer[DemoPlayer.RENDERER_COUNT];
    renderers[DemoPlayer.TYPE_VIDEO] = videoRenderer;
    renderers[DemoPlayer.TYPE_AUDIO] = audioRenderer;
    renderers[DemoPlayer.TYPE_DEBUG] = debugRenderer;
    callback.onRenderers(trackNames, multiTrackChunkSources, renderers);
  }
@override public void onmanifest(string contentid, mediapresentationdescription manifest) { handler mainhandler = player.getmainhandler(); loadcontrol loadcontrol = new defaultloadcontrol(new bufferpool(buffer_segment_size)); defaultbandwidthmeter bandwidthmeter = new defaultbandwidthmeter(mainhandler, player); int maxdecodableframesize = mediacodecutil.maxh264decodableframesize(); arraylist<representation> audiorepresentationslist = new arraylist<representation>(); arraylist<representation> videorepresentationslist = new arraylist<representation>(); period period = manifest.periods.get(0); boolean hascontentprotection = false; for (int i = 0; i < period.adaptationsets.size(); i++) { adaptationset adaptationset = period.adaptationsets.get(i); hascontentprotection |= adaptationset.hascontentprotection(); int adaptationsettype = adaptationset.type; for (int j = 0; j < adaptationset.representations.size(); j++) { representation representation = adaptationset.representations.get(j); if (adaptationsettype == adaptationset.type_audio) { audiorepresentationslist.add(representation); } else if (adaptationsettype == adaptationset.type_video) { format format = representation.format; if (format.width * format.height <= maxdecodableframesize) { videorepresentationslist.add(representation); } else { } } } } representation[] videorepresentations = new representation[videorepresentationslist.size()]; videorepresentationslist.toarray(videorepresentations); drmsessionmanager drmsessionmanager = null; if (hascontentprotection) { if (util.sdk_int < 18) { callback.onrendererserror(new unsupportedoperationexception( "protected content not supported on api level " + util.sdk_int)); return; } try { pair<drmsessionmanager, boolean> drmsessionmanagerdata = v18compat.getdrmsessionmanagerdata(player, drmcallback); drmsessionmanager = drmsessionmanagerdata.first; if (!drmsessionmanagerdata.second) { videorepresentations = getsdrepresentations(videorepresentations); } } catch (exception e) { callback.onrendererserror(e); return; } } datasource videodatasource = new httpdatasource(useragent, null, bandwidthmeter); chunksource videochunksource; string mimetype = videorepresentations[0].format.mimetype; if (mimetype.equals(mimetypes.video_mp4)) { videochunksource = new dashmp4chunksource(videodatasource, new adaptiveevaluator(bandwidthmeter), videorepresentations); } else if (mimetype.equals(mimetypes.video_webm)) { videorepresentations = getsdrepresentations(videorepresentations); videochunksource = new dashwebmchunksource(videodatasource, new adaptiveevaluator(bandwidthmeter), videorepresentations); } else { throw new illegalstateexception("unexpected mime type: " + mimetype); } chunksamplesource videosamplesource = new chunksamplesource(videochunksource, loadcontrol, video_buffer_segments * buffer_segment_size, true, mainhandler, player, demoplayer.type_video); mediacodecvideotrackrenderer videorenderer = new mediacodecvideotrackrenderer(videosamplesource, drmsessionmanager, true, mediacodec.video_scaling_mode_scale_to_fit, 5000, mainhandler, player, 50); final string[] audiotracknames; final multitrackchunksource audiochunksource; final mediacodecaudiotrackrenderer audiorenderer; if (audiorepresentationslist.isempty()) { audiotracknames = null; audiochunksource = null; audiorenderer = null; } else { datasource audiodatasource = new httpdatasource(useragent, null, bandwidthmeter); audiotracknames = new string[audiorepresentationslist.size()]; chunksource[] audiochunksources = new chunksource[audiorepresentationslist.size()]; formatevaluator audioevaluator = new formatevaluator.fixedevaluator(); for (int i = 0; i < audiorepresentationslist.size(); i++) { representation representation = audiorepresentationslist.get(i); format format = representation.format; audiotracknames[i] = format.id + " (" + format.numchannels + "ch, " + format.audiosamplingrate + "hz)"; audiochunksources[i] = new dashmp4chunksource(audiodatasource, audioevaluator, representation); } audiochunksource = new multitrackchunksource(audiochunksources); samplesource audiosamplesource = new chunksamplesource(audiochunksource, loadcontrol, audio_buffer_segments * buffer_segment_size, true, mainhandler, player, demoplayer.type_audio); audiorenderer = new mediacodecaudiotrackrenderer(audiosamplesource, drmsessionmanager, true, mainhandler, player); } trackrenderer debugrenderer = debugtextview != null ? new debugtrackrenderer(debugtextview, videorenderer, videosamplesource) : null; string[][] tracknames = new string[demoplayer.renderer_count][]; tracknames[demoplayer.type_audio] = audiotracknames; multitrackchunksource[] multitrackchunksources = new multitrackchunksource[demoplayer.renderer_count]; multitrackchunksources[demoplayer.type_audio] = audiochunksource; trackrenderer[] renderers = new trackrenderer[demoplayer.renderer_count]; renderers[demoplayer.type_video] = videorenderer; renderers[demoplayer.type_audio] = audiorenderer; renderers[demoplayer.type_debug] = debugrenderer; callback.onrenderers(tracknames, multitrackchunksources, renderers); }