Java 类com.google.android.exoplayer.hls.DefaultHlsTrackSelector 实例源码

项目:danish-media-license    文件:HlsRendererBuilder.java   
@Override
public void onSingleManifest(HlsPlaylist manifest) {
  if (canceled) {
    return;
  }

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

  // Build the video/audio/metadata renderers.
  DataSource dataSource = createDataSource(context, userAgent, bandwidthMeter);
  HlsChunkSource chunkSource = new HlsChunkSource(true /* isMaster */, dataSource, url,
      manifest, DefaultHlsTrackSelector.newDefaultInstance(context), bandwidthMeter,
      timestampAdjusterProvider, HlsChunkSource.ADAPTIVE_MODE_SPLICE);
  HlsSampleSource sampleSource = new HlsSampleSource(chunkSource, loadControl,
      MAIN_BUFFER_SEGMENTS * BUFFER_SEGMENT_SIZE, mainHandler, player, DemoPlayer.TYPE_VIDEO);
  MediaCodecVideoTrackRenderer videoRenderer = new MediaCodecVideoTrackRenderer(context,
      sampleSource, MediaCodecSelector.DEFAULT, MediaCodec.VIDEO_SCALING_MODE_SCALE_TO_FIT,
      5000, mainHandler, player, 50);
  final MediaCodecAudioTrackRenderer audioRenderer = new MediaCodecAudioTrackRenderer(
      sampleSource, MediaCodecSelector.DEFAULT, null, true, player.getMainHandler(), player,
      AudioCapabilities.getCapabilities(context), AudioManager.STREAM_MUSIC);
  final MetadataTrackRenderer<List<Id3Frame>> id3Renderer = new MetadataTrackRenderer<>(
      sampleSource, new Id3Parser(), player, mainHandler.getLooper());

  TrackRenderer[] renderers = new TrackRenderer[DemoPlayer.RENDERER_COUNT];
  renderers[DemoPlayer.TYPE_VIDEO] = videoRenderer;
  renderers[DemoPlayer.TYPE_AUDIO] = audioRenderer;
  renderers[DemoPlayer.TYPE_METADATA] = id3Renderer;
  player.onRenderers(renderers, bandwidthMeter);
}
项目:luxunPro    文件:HlsRenderBuilder.java   
protected void buildTrackRenderers(HlsPlaylist playlist, boolean hasClosedCaptions, boolean hasMultipleAudioTracks) {
    LoadControl loadControl = new DefaultLoadControl(new DefaultAllocator(BUFFER_SEGMENT_SIZE));
    DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(player.getMainHandler(), player);
    PtsTimestampAdjusterProvider timestampAdjusterProvider = new PtsTimestampAdjusterProvider();


    //Create the Sample Source to be used by the Video Renderer
    DataSource dataSourceVideo = createDataSource(okHttpClient, bandwidthMeter, userAgent);
    HlsChunkSource chunkSourceVideo = new HlsChunkSource(true, dataSourceVideo, playlist, DefaultHlsTrackSelector.newDefaultInstance(context),
            bandwidthMeter, timestampAdjusterProvider);
    HlsSampleSource sampleSourceVideo = new HlsSampleSource(chunkSourceVideo, loadControl,
            BUFFER_SEGMENTS_TOTAL * BUFFER_SEGMENT_SIZE, player.getMainHandler(), player, EMExoPlayer.RENDER_VIDEO);


    //Create the Sample Source to be used by the Audio Renderer
    DataSource dataSourceAudio = new DefaultUriDataSource(context, bandwidthMeter, userAgent);
    HlsChunkSource chunkSourceAudio = new HlsChunkSource(false, dataSourceAudio, playlist, DefaultHlsTrackSelector.newAudioInstance(),
            bandwidthMeter, timestampAdjusterProvider);
    HlsSampleSource sampleSourceAudio = new HlsSampleSource(chunkSourceAudio, loadControl, BUFFER_SEGMENTS_AUDIO * BUFFER_SEGMENT_SIZE,
            player.getMainHandler(), player, EMExoPlayer.RENDER_AUDIO);
    SampleSource[] sampleSourcesAudio = hasMultipleAudioTracks ? new SampleSource[] {sampleSourceVideo, sampleSourceAudio} : new SampleSource[] {sampleSourceVideo};


    //Create the Sample Source to be used by the Closed Captions Renderer
    DataSource dataSourceCC = createDataSource(okHttpClient, bandwidthMeter, userAgent);
    HlsChunkSource chunkSourceCC = new HlsChunkSource(false, dataSourceCC, playlist, DefaultHlsTrackSelector.newSubtitleInstance(),
            bandwidthMeter, timestampAdjusterProvider);
    HlsSampleSource sampleSourceCC = new HlsSampleSource(chunkSourceCC, loadControl,
            BUFFER_SEGMENTS_TEXT * BUFFER_SEGMENT_SIZE, player.getMainHandler(), player, EMExoPlayer.RENDER_CLOSED_CAPTION);


    //Build the renderers
    MediaCodecVideoTrackRenderer videoRenderer = new MediaCodecVideoTrackRenderer(context, sampleSourceVideo, MediaCodecSelector.DEFAULT,
            MediaCodec.VIDEO_SCALING_MODE_SCALE_TO_FIT, MAX_JOIN_TIME, player.getMainHandler(), player, DROPPED_FRAME_NOTIFICATION_AMOUNT);
    EMMediaCodecAudioTrackRenderer audioRenderer = new EMMediaCodecAudioTrackRenderer(sampleSourcesAudio, MediaCodecSelector.DEFAULT, null, true,
            player.getMainHandler(), player, AudioCapabilities.getCapabilities(context), streamType);
    TrackRenderer captionsRenderer = hasClosedCaptions ? new TextTrackRenderer(sampleSourceCC, player, player.getMainHandler().getLooper()) :
            new Eia608TrackRenderer(sampleSourceVideo, player, player.getMainHandler().getLooper());
    MetadataTrackRenderer<List<Id3Frame>> id3Renderer = new MetadataTrackRenderer<>(sampleSourceVideo, new Id3Parser(),
            player, player.getMainHandler().getLooper());


    //Populate the Render list to pass back to the callback
    TrackRenderer[] renderers = new TrackRenderer[EMExoPlayer.RENDER_COUNT];
    renderers[EMExoPlayer.RENDER_VIDEO] = videoRenderer;
    renderers[EMExoPlayer.RENDER_AUDIO] = audioRenderer;
    renderers[EMExoPlayer.RENDER_CLOSED_CAPTION] = captionsRenderer;
    renderers[EMExoPlayer.RENDER_TIMED_METADATA] = id3Renderer;
    player.onRenderers(renderers, bandwidthMeter);
}