com.google.android.exoplayer.TrackRenderer Java Examples

The following examples show how to use com.google.android.exoplayer.TrackRenderer. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ExtractorRendererBuilder.java    From google-media-framework-android with Apache License 2.0 6 votes vote down vote up
@Override
public void buildRenderers(ExoplayerWrapper player) {
    Allocator allocator = new DefaultAllocator(BUFFER_SEGMENT_SIZE);

    // Build the video and audio renderers.
    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);
    MediaCodecVideoTrackRenderer videoRenderer = new MediaCodecVideoTrackRenderer(context,
            sampleSource, MediaCodecSelector.DEFAULT, MediaCodec.VIDEO_SCALING_MODE_SCALE_TO_FIT,
            5000, player.getMainHandler(), player, 50);
    MediaCodecAudioTrackRenderer audioRenderer = new MediaCodecAudioTrackRenderer(sampleSource,
            MediaCodecSelector.DEFAULT, null, true, player.getMainHandler(), player,
            AudioCapabilities.getCapabilities(context), AudioManager.STREAM_MUSIC);
    TrackRenderer textRenderer = new TextTrackRenderer(sampleSource, player,
            player.getMainHandler().getLooper());

    // Invoke the callback.
    TrackRenderer[] renderers = new TrackRenderer[ExoplayerWrapper.RENDERER_COUNT];
    renderers[ExoplayerWrapper.TYPE_VIDEO] = videoRenderer;
    renderers[ExoplayerWrapper.TYPE_AUDIO] = audioRenderer;
    renderers[ExoplayerWrapper.TYPE_TEXT] = textRenderer;
    player.onRenderers(renderers, bandwidthMeter);
}
 
Example #2
Source File: ExtractorRendererBuilder.java    From AndroidTvDemo with Apache License 2.0 6 votes vote down vote up
@Override
public void buildRenderers(DemoPlayer player) {
  Allocator allocator = new DefaultAllocator(BUFFER_SEGMENT_SIZE);
  Handler mainHandler = player.getMainHandler();

  // Build the video and audio renderers.
  DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(mainHandler, null);
  DataSource dataSource = new DefaultUriDataSource(context, bandwidthMeter, userAgent);
  ExtractorSampleSource sampleSource = new ExtractorSampleSource(uri, dataSource, allocator,
      BUFFER_SEGMENT_COUNT * BUFFER_SEGMENT_SIZE, mainHandler, player, 0);
  MediaCodecVideoTrackRenderer videoRenderer = new MediaCodecVideoTrackRenderer(context,
      sampleSource, MediaCodecSelector.DEFAULT, MediaCodec.VIDEO_SCALING_MODE_SCALE_TO_FIT, 5000,
      mainHandler, player, 50);
  MediaCodecAudioTrackRenderer audioRenderer = new MediaCodecAudioTrackRenderer(sampleSource,
      MediaCodecSelector.DEFAULT, null, true, mainHandler, player,
      AudioCapabilities.getCapabilities(context), AudioManager.STREAM_MUSIC);
  TrackRenderer textRenderer = new TextTrackRenderer(sampleSource, 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);
}
 
Example #3
Source File: DemoPlayer.java    From WliveTV with Apache License 2.0 6 votes vote down vote up
/**
 * Invoked with the results from a {link RendererBuilder}.
 *
 * @param renderers Renderers indexed by {link DemoPlayer} TYPE_* constants. An individual
 *     element may be null if there do not exist tracks of the corresponding type.
 * @param bandwidthMeter Provides an estimate of the currently available bandwidth. May be null.
 */
/* package */ void onRenderers(TrackRenderer[] renderers, BandwidthMeter bandwidthMeter) {
  for (int i = 0; i < RENDERER_COUNT; i++) {
    if (renderers[i] == null) {
      // Convert a null renderer to a dummy renderer.
      renderers[i] = new DummyTrackRenderer();
    }
  }
  // Complete preparation.
  this.videoRenderer = renderers[TYPE_VIDEO];
  this.codecCounters = videoRenderer instanceof MediaCodecTrackRenderer
      ? ((MediaCodecTrackRenderer) videoRenderer).codecCounters
      : renderers[TYPE_AUDIO] instanceof MediaCodecTrackRenderer
      ? ((MediaCodecTrackRenderer) renderers[TYPE_AUDIO]).codecCounters : null;
  this.bandwidthMeter = bandwidthMeter;
  pushSurface(false);
  player.prepare(renderers);
  rendererBuildingState = RENDERER_BUILDING_STATE_BUILT;
}
 
Example #4
Source File: ExoPlayerInputProvider.java    From ChannelSurfer with MIT License 6 votes vote down vote up
/**
 * Will load and begin to play any RTMP, HLS, or MPEG2-DASH stream
 * Should also be able to play local videos and audio files
 * @param uri The URL where the file resides
 */
public void play(String uri) {
    tvInputPlayer.setSurface(mSurface);
    try {
        Log.d(TAG, "Play "+uri+"; "+uri.indexOf("asset:///"));
        if(uri.contains("asset:///")) {
            Log.i(TAG, "Is a local file");
            DataSource dataSource=new AssetDataSource(getApplicationContext());
            ExtractorSampleSource extractorSampleSource=new ExtractorSampleSource(Uri.parse(uri),dataSource,new DefaultAllocator(1000),5000);
            TrackRenderer audio=new MediaCodecAudioTrackRenderer(extractorSampleSource,null,null,true);
            tvInputPlayer.prepare(audio, null, null);
        } else {
            tvInputPlayer.prepare(getApplicationContext(), Uri.parse(uri), TvInputPlayer.SOURCE_TYPE_HLS);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    tvInputPlayer.setPlayWhenReady(true);

}
 
Example #5
Source File: DemoPlayer.java    From droidkaigi2016 with Apache License 2.0 6 votes vote down vote up
/**
 * Invoked with the results from a {@link RendererBuilder}.
 *
 * @param renderers Renderers indexed by {@link DemoPlayer} TYPE_* constants. An individual
 *     element may be null if there do not exist tracks of the corresponding type.
 * @param bandwidthMeter Provides an estimate of the currently available bandwidth. May be null.
 */
/* package */ void onRenderers(TrackRenderer[] renderers, BandwidthMeter bandwidthMeter) {
  for (int i = 0; i < RENDERER_COUNT; i++) {
    if (renderers[i] == null) {
      // Convert a null renderer to a dummy renderer.
      renderers[i] = new DummyTrackRenderer();
    }
  }
  // Complete preparation.
  this.videoRenderer = renderers[TYPE_VIDEO];
  this.codecCounters = videoRenderer instanceof MediaCodecTrackRenderer
      ? ((MediaCodecTrackRenderer) videoRenderer).codecCounters
      : renderers[TYPE_AUDIO] instanceof MediaCodecTrackRenderer
      ? ((MediaCodecTrackRenderer) renderers[TYPE_AUDIO]).codecCounters : null;
  this.bandwidthMeter = bandwidthMeter;
  pushSurface(false);
  player.prepare(renderers);
  rendererBuildingState = RENDERER_BUILDING_STATE_BUILT;
}
 
Example #6
Source File: ExtractorRendererBuilder.java    From talk-android with MIT License 6 votes vote down vote up
@Override
public void buildRenderers(DemoPlayer player) {
  Allocator allocator = new DefaultAllocator(BUFFER_SEGMENT_SIZE);

  // Build the video and audio renderers.
  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);
  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[DemoPlayer.RENDERER_COUNT];
  renderers[DemoPlayer.TYPE_VIDEO] = videoRenderer;
  renderers[DemoPlayer.TYPE_AUDIO] = audioRenderer;
  renderers[DemoPlayer.TYPE_TEXT] = textRenderer;
  player.onRenderers(renderers, bandwidthMeter);
}
 
Example #7
Source File: DemoPlayer.java    From talk-android with MIT License 6 votes vote down vote up
/**
 * Invoked with the results from a {link RendererBuilder}.
 *
 * @param renderers Renderers indexed by {link DemoPlayer} TYPE_* constants. An individual
 *     element may be null if there do not exist tracks of the corresponding type.
 * @param bandwidthMeter Provides an estimate of the currently available bandwidth. May be null.
 */
/* package */ void onRenderers(TrackRenderer[] renderers, BandwidthMeter bandwidthMeter) {
  for (int i = 0; i < RENDERER_COUNT; i++) {
    if (renderers[i] == null) {
      // Convert a null renderer to a dummy renderer.
      renderers[i] = new DummyTrackRenderer();
    }
  }
  // Complete preparation.
  this.videoRenderer = renderers[TYPE_VIDEO];
  this.codecCounters = videoRenderer instanceof MediaCodecTrackRenderer
      ? ((MediaCodecTrackRenderer) videoRenderer).codecCounters
      : renderers[TYPE_AUDIO] instanceof MediaCodecTrackRenderer
      ? ((MediaCodecTrackRenderer) renderers[TYPE_AUDIO]).codecCounters : null;
  this.bandwidthMeter = bandwidthMeter;
  pushSurface(false);
  player.prepare(renderers);
  rendererBuildingState = RENDERER_BUILDING_STATE_BUILT;
}
 
Example #8
Source File: ExtractorRendererBuilder.java    From ShareBox with Apache License 2.0 6 votes vote down vote up
@Override
public void buildRenderers(DemoPlayer player) {
  Allocator allocator = new DefaultAllocator(BUFFER_SEGMENT_SIZE);
  Handler mainHandler = player.getMainHandler();

  // Build the video and audio renderers.
  DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(mainHandler, null);
  DataSource dataSource = new DefaultUriDataSource(context, bandwidthMeter, userAgent);
  ExtractorSampleSource sampleSource = new ExtractorSampleSource(uri, dataSource, allocator,
      BUFFER_SEGMENT_COUNT * BUFFER_SEGMENT_SIZE, mainHandler, player, 0);
  MediaCodecVideoTrackRenderer videoRenderer = new MediaCodecVideoTrackRenderer(context,
      sampleSource, MediaCodecSelector.DEFAULT, MediaCodec.VIDEO_SCALING_MODE_SCALE_TO_FIT, 5000,
      mainHandler, player, 50);
  MediaCodecAudioTrackRenderer audioRenderer = new MediaCodecAudioTrackRenderer(sampleSource,
      MediaCodecSelector.DEFAULT, null, true, mainHandler, player,
      AudioCapabilities.getCapabilities(context), AudioManager.STREAM_MUSIC);
  TrackRenderer textRenderer = new TextTrackRenderer(sampleSource, 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);
}
 
Example #9
Source File: DemoPlayer.java    From ShareBox with Apache License 2.0 6 votes vote down vote up
/**
 * Invoked with the results from a {link RendererBuilder}.
 *
 * @param renderers Renderers indexed by {link DemoPlayer} TYPE_* constants. An individual
 *     element may be null if there do not exist tracks of the corresponding type.
 * @param bandwidthMeter Provides an estimate of the currently available bandwidth. May be null.
 */
/* package */ void onRenderers(TrackRenderer[] renderers, BandwidthMeter bandwidthMeter) {
  for (int i = 0; i < RENDERER_COUNT; i++) {
    if (renderers[i] == null) {
      // Convert a null renderer to a dummy renderer.
      renderers[i] = new DummyTrackRenderer();
    }
  }
  // Complete preparation.
  this.videoRenderer = renderers[TYPE_VIDEO];
  this.codecCounters = videoRenderer instanceof MediaCodecTrackRenderer
      ? ((MediaCodecTrackRenderer) videoRenderer).codecCounters
      : renderers[TYPE_AUDIO] instanceof MediaCodecTrackRenderer
      ? ((MediaCodecTrackRenderer) renderers[TYPE_AUDIO]).codecCounters : null;
  this.bandwidthMeter = bandwidthMeter;
  pushSurface(false);
  player.prepare(renderers);
  rendererBuildingState = RENDERER_BUILDING_STATE_BUILT;
}
 
Example #10
Source File: ExtractorRendererBuilder.java    From WliveTV with Apache License 2.0 6 votes vote down vote up
@Override
public void buildRenderers(DemoPlayer player) {
  Allocator allocator = new DefaultAllocator(BUFFER_SEGMENT_SIZE);

  // Build the video and audio renderers.
  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);
  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[DemoPlayer.RENDERER_COUNT];
  renderers[DemoPlayer.TYPE_VIDEO] = videoRenderer;
  renderers[DemoPlayer.TYPE_AUDIO] = audioRenderer;
  renderers[DemoPlayer.TYPE_TEXT] = textRenderer;
  player.onRenderers(renderers, bandwidthMeter);
}
 
Example #11
Source File: DemoPlayer.java    From Android-Example-HLS-ExoPlayer with Apache License 2.0 6 votes vote down vote up
/**
 * Invoked with the results from a {@link RendererBuilder}.
 *
 * @param renderers Renderers indexed by {@link DemoPlayer} TYPE_* constants. An individual
 *     element may be null if there do not exist tracks of the corresponding type.
 * @param bandwidthMeter Provides an estimate of the currently available bandwidth. May be null.
 */
/* package */ void onRenderers(TrackRenderer[] renderers, BandwidthMeter bandwidthMeter) {
  for (int i = 0; i < RENDERER_COUNT; i++) {
    if (renderers[i] == null) {
      // Convert a null renderer to a dummy renderer.
      renderers[i] = new DummyTrackRenderer();
    }
  }
  // Complete preparation.
  this.videoRenderer = renderers[TYPE_VIDEO];
  this.codecCounters = videoRenderer instanceof MediaCodecTrackRenderer
      ? ((MediaCodecTrackRenderer) videoRenderer).codecCounters
      : renderers[TYPE_AUDIO] instanceof MediaCodecTrackRenderer
      ? ((MediaCodecTrackRenderer) renderers[TYPE_AUDIO]).codecCounters : null;
  this.bandwidthMeter = bandwidthMeter;
  pushSurface(false);
  player.prepare(renderers);
  rendererBuildingState = RENDERER_BUILDING_STATE_BUILT;
}
 
Example #12
Source File: PlayerActivity.java    From android-tv-leanback with Apache License 2.0 6 votes vote down vote up
private void preparePlayer() {

        SampleSource sampleSource =
                new FrameworkSampleSource(this, Uri.parse(mVideo.getContentUrl()), /* headers */ null, RENDERER_COUNT);

        // Build the track renderers
        videoRenderer = new MediaCodecVideoTrackRenderer(sampleSource, MediaCodec.VIDEO_SCALING_MODE_SCALE_TO_FIT);
        TrackRenderer audioRenderer = new MediaCodecAudioTrackRenderer(sampleSource);


        // Setup the player
        player = ExoPlayer.Factory.newInstance(RENDERER_COUNT, 1000, 5000);
        player.addListener(this);
        // Build the player controls
        mediaController.setMediaPlayer(new PlayerControl(player));
        mediaController.setEnabled(true);
        player.prepare(videoRenderer, audioRenderer);
    }
 
Example #13
Source File: PlayerActivity.java    From android-tv-leanback with Apache License 2.0 6 votes vote down vote up
private void preparePlayer() {

        SampleSource sampleSource =
                new FrameworkSampleSource(this, Uri.parse(mVideo.getContentUrl()), /* headers */ null, RENDERER_COUNT);

        // Build the track renderers
        videoRenderer = new MediaCodecVideoTrackRenderer(sampleSource, MediaCodec.VIDEO_SCALING_MODE_SCALE_TO_FIT);
        TrackRenderer audioRenderer = new MediaCodecAudioTrackRenderer(sampleSource);

        // Setup the player
        player = ExoPlayer.Factory.newInstance(RENDERER_COUNT, 1000, 5000);
        player.addListener(this);
        // Build the player controls
        mediaController.setMediaPlayer(new PlayerControl(player));
        mediaController.setEnabled(true);
        player.prepare(videoRenderer, audioRenderer);
    }
 
Example #14
Source File: PlayerActivity.java    From android-tv-leanback with Apache License 2.0 6 votes vote down vote up
private void preparePlayer() {

        SampleSource sampleSource =
                new FrameworkSampleSource(this, Uri.parse(mVideo.getContentUrl()), /* headers */ null, RENDERER_COUNT);

        // Build the track renderers
        videoRenderer = new MediaCodecVideoTrackRenderer(sampleSource, MediaCodec.VIDEO_SCALING_MODE_SCALE_TO_FIT);
        TrackRenderer audioRenderer = new MediaCodecAudioTrackRenderer(sampleSource);

        // Setup the player
        player = ExoPlayer.Factory.newInstance(RENDERER_COUNT, 1000, 5000);
        player.addListener(this);
        // Build the player controls
        mediaController.setMediaPlayer(new PlayerControl(player));
        mediaController.setEnabled(true);
        player.prepare(videoRenderer, audioRenderer);
    }
 
Example #15
Source File: PlayerActivity.java    From android-tv-leanback with Apache License 2.0 6 votes vote down vote up
private void preparePlayer() {

        SampleSource sampleSource =
                new FrameworkSampleSource(this, Uri.parse(mVideo.getContentUrl()), /* headers */ null, RENDERER_COUNT);

        // Build the track renderers
        videoRenderer = new MediaCodecVideoTrackRenderer(sampleSource, MediaCodec.VIDEO_SCALING_MODE_SCALE_TO_FIT);
        TrackRenderer audioRenderer = new MediaCodecAudioTrackRenderer(sampleSource);

        // Setup the player
        player = ExoPlayer.Factory.newInstance(RENDERER_COUNT, 1000, 5000);
        player.addListener(this);
        // Build the player controls
        mediaController.setMediaPlayer(new PlayerControl(player));
        mediaController.setEnabled(true);
        player.prepare(videoRenderer, audioRenderer);
    }
 
Example #16
Source File: AssetsRendererBuilder.java    From exoplayer-textureview with Apache License 2.0 6 votes vote down vote up
@Override
protected void buildRenderers(RendererBuilderCallback callback) {
    Allocator allocator = new DefaultAllocator(bufferSegmentSize);
    DataSource dataSource = new DefaultUriDataSource(context, bandwidthMeter, userAgent);
    ExtractorSampleSource sampleSource = new ExtractorSampleSource(uri, dataSource,
            allocator, bufferSegmentSize * bufferSegmentCount);
    MediaCodecVideoTrackRenderer videoRenderer = new MediaCodecVideoTrackRenderer(context,
            sampleSource, MediaCodecSelector.DEFAULT,
            MediaCodec.VIDEO_SCALING_MODE_SCALE_TO_FIT, 5000,
            eventHandler, eventProxy, 50);
    MediaCodecAudioTrackRenderer audioRenderer = new MediaCodecAudioTrackRenderer(sampleSource,
            MediaCodecSelector.DEFAULT, null, true, eventHandler, eventProxy,
            AudioCapabilities.getCapabilities(context), AudioManager.STREAM_MUSIC);

    TrackRenderer textRenderer = new TextTrackRenderer(sampleSource, eventProxy,
            eventHandler.getLooper());

    // Invoke the callback.
    TrackRenderer[] renderers = new TrackRenderer[Player.RENDERER_COUNT];
    renderers[Player.TYPE_VIDEO] = videoRenderer;
    renderers[Player.TYPE_AUDIO] = audioRenderer;
    renderers[Player.TYPE_TEXT] = textRenderer;
    callback.onRenderers(renderers, bandwidthMeter);
}
 
Example #17
Source File: DefaultRendererBuilder.java    From Exoplayer_VLC with Apache License 2.0 6 votes vote down vote up
@Override
public void buildRenderers(DemoPlayer player, RendererBuilderCallback callback) {
  // Build the video and audio renderers.
  DefaultSampleSource sampleSource =
      new DefaultSampleSource(new FrameworkSampleExtractor(context, uri, null), 2);
  MediaCodecVideoTrackRenderer videoRenderer = new MediaCodecVideoTrackRenderer(sampleSource,
      null, true, MediaCodec.VIDEO_SCALING_MODE_SCALE_TO_FIT, 5000, null, player.getMainHandler(),
      player, 50);
  MediaCodecAudioTrackRenderer audioRenderer = new MediaCodecAudioTrackRenderer(sampleSource,
      null, true, player.getMainHandler(), player);

  // Build the debug renderer.
  TrackRenderer debugRenderer = debugTextView != null
      ? new DebugTrackRenderer(debugTextView, videoRenderer)
      : null;

  // Invoke the callback.
  TrackRenderer[] renderers = new TrackRenderer[DemoPlayer.RENDERER_COUNT];
  renderers[DemoPlayer.TYPE_VIDEO] = videoRenderer;
  renderers[DemoPlayer.TYPE_AUDIO] = audioRenderer;
  renderers[DemoPlayer.TYPE_DEBUG] = debugRenderer;
  callback.onRenderers(null, null, renderers);
}
 
Example #18
Source File: HlsRendererBuilder.java    From Exoplayer_VLC with Apache License 2.0 6 votes vote down vote up
@Override
public void onManifest(String contentId, HlsPlaylist manifest) {
  DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();

  DataSource dataSource = new UriDataSource(userAgent, bandwidthMeter);
  HlsChunkSource chunkSource = new HlsChunkSource(dataSource, url, manifest, bandwidthMeter, null,
      HlsChunkSource.ADAPTIVE_MODE_SPLICE);
  HlsSampleSource sampleSource = new HlsSampleSource(chunkSource, true, 3);
  MediaCodecVideoTrackRenderer videoRenderer = new MediaCodecVideoTrackRenderer(sampleSource,
      MediaCodec.VIDEO_SCALING_MODE_SCALE_TO_FIT, 5000, player.getMainHandler(), player, 50);
  MediaCodecAudioTrackRenderer audioRenderer = new MediaCodecAudioTrackRenderer(sampleSource);

  MetadataTrackRenderer<Map<String, Object>> id3Renderer =
      new MetadataTrackRenderer<Map<String, Object>>(sampleSource, new Id3Parser(),
          player.getId3MetadataRenderer(), player.getMainHandler().getLooper());

  Eia608TrackRenderer closedCaptionRenderer = new Eia608TrackRenderer(sampleSource, player,
      player.getMainHandler().getLooper());

  TrackRenderer[] renderers = new TrackRenderer[DemoPlayer.RENDERER_COUNT];
  renderers[DemoPlayer.TYPE_VIDEO] = videoRenderer;
  renderers[DemoPlayer.TYPE_AUDIO] = audioRenderer;
  renderers[DemoPlayer.TYPE_TIMED_METADATA] = id3Renderer;
  renderers[DemoPlayer.TYPE_TEXT] = closedCaptionRenderer;
  callback.onRenderers(null, null, renderers);
}
 
Example #19
Source File: Eia608TrackRenderer.java    From Exoplayer_VLC with Apache License 2.0 6 votes vote down vote up
@Override
protected int doPrepare() throws ExoPlaybackException {
  try {
    boolean sourcePrepared = source.prepare();
    if (!sourcePrepared) {
      return TrackRenderer.STATE_UNPREPARED;
    }
  } catch (IOException e) {
    throw new ExoPlaybackException(e);
  }
  for (int i = 0; i < source.getTrackCount(); i++) {
    if (eia608Parser.canParse(source.getTrackInfo(i).mimeType)) {
      trackIndex = i;
      return TrackRenderer.STATE_PREPARED;
    }
  }
  return TrackRenderer.STATE_IGNORE;
}
 
Example #20
Source File: TextTrackRenderer.java    From Exoplayer_VLC with Apache License 2.0 6 votes vote down vote up
@Override
protected int doPrepare() throws ExoPlaybackException {
  try {
    boolean sourcePrepared = source.prepare();
    if (!sourcePrepared) {
      return TrackRenderer.STATE_UNPREPARED;
    }
  } catch (IOException e) {
    throw new ExoPlaybackException(e);
  }
  for (int i = 0; i < subtitleParsers.length; i++) {
    for (int j = 0; j < source.getTrackCount(); j++) {
      if (subtitleParsers[i].canParse(source.getTrackInfo(j).mimeType)) {
        parserIndex = i;
        trackIndex = j;
        return TrackRenderer.STATE_PREPARED;
      }
    }
  }
  return TrackRenderer.STATE_IGNORE;
}
 
Example #21
Source File: MetadataTrackRenderer.java    From Exoplayer_VLC with Apache License 2.0 6 votes vote down vote up
@Override
protected int doPrepare() throws ExoPlaybackException {
  try {
    boolean sourcePrepared = source.prepare();
    if (!sourcePrepared) {
      return TrackRenderer.STATE_UNPREPARED;
    }
  } catch (IOException e) {
    throw new ExoPlaybackException(e);
  }
  for (int i = 0; i < source.getTrackCount(); i++) {
    if (metadataParser.canParse(source.getTrackInfo(i).mimeType)) {
      trackIndex = i;
      return TrackRenderer.STATE_PREPARED;
    }
  }
  return TrackRenderer.STATE_IGNORE;
}
 
Example #22
Source File: ChunkSampleSource.java    From Exoplayer_VLC with Apache License 2.0 6 votes vote down vote up
@Override
public long getBufferedPositionUs() {
  Assertions.checkState(state == STATE_ENABLED);
  if (isPendingReset()) {
    return pendingResetPositionUs;
  }
  MediaChunk mediaChunk = mediaChunks.getLast();
  Chunk currentLoadable = currentLoadableHolder.chunk;
  if (currentLoadable != null && mediaChunk == currentLoadable) {
    // Linearly interpolate partially-fetched chunk times.
    long chunkLength = mediaChunk.getLength();
    if (chunkLength != C.LENGTH_UNBOUNDED && chunkLength != 0) {
      return mediaChunk.startTimeUs + ((mediaChunk.endTimeUs - mediaChunk.startTimeUs) *
          mediaChunk.bytesLoaded()) / chunkLength;
    } else {
      return mediaChunk.startTimeUs;
    }
  } else if (mediaChunk.isLastChunk()) {
    return TrackRenderer.END_OF_TRACK_US;
  } else {
    return mediaChunk.endTimeUs;
  }
}
 
Example #23
Source File: DemoPlayer.java    From droidkaigi2016 with Apache License 2.0 6 votes vote down vote up
/**
 * Invoked with the results from a {@link RendererBuilder}.
 *
 * @param renderers Renderers indexed by {@link DemoPlayer} TYPE_* constants. An individual
 *     element may be null if there do not exist tracks of the corresponding type.
 * @param bandwidthMeter Provides an estimate of the currently available bandwidth. May be null.
 */
/* package */ void onRenderers(TrackRenderer[] renderers, BandwidthMeter bandwidthMeter) {
  for (int i = 0; i < RENDERER_COUNT; i++) {
    if (renderers[i] == null) {
      // Convert a null renderer to a dummy renderer.
      renderers[i] = new DummyTrackRenderer();
    }
  }
  // Complete preparation.
  this.videoRenderer = renderers[TYPE_VIDEO];
  this.codecCounters = videoRenderer instanceof MediaCodecTrackRenderer
      ? ((MediaCodecTrackRenderer) videoRenderer).codecCounters
      : renderers[TYPE_AUDIO] instanceof MediaCodecTrackRenderer
      ? ((MediaCodecTrackRenderer) renderers[TYPE_AUDIO]).codecCounters : null;
  this.bandwidthMeter = bandwidthMeter;
  pushSurface(false);
  player.prepare(renderers);
  rendererBuildingState = RENDERER_BUILDING_STATE_BUILT;
}
 
Example #24
Source File: DefaultRendererBuilder.java    From Mobilyzer with Apache License 2.0 6 votes vote down vote up
@Override
public void buildRenderers(DemoPlayer player, RendererBuilderCallback callback) {
  // Build the video and audio renderers.
  FrameworkSampleSource sampleSource = new FrameworkSampleSource(context, uri, null, 2);
  MediaCodecVideoTrackRenderer videoRenderer = new MediaCodecVideoTrackRenderer(sampleSource,
      null, true, MediaCodec.VIDEO_SCALING_MODE_SCALE_TO_FIT, 5000,
      player.getMainHandler(), player, 1);
  MediaCodecAudioTrackRenderer audioRenderer = new MediaCodecAudioTrackRenderer(sampleSource,
      null, true, player.getMainHandler(), player);

  // Build the debug renderer.
  TrackRenderer debugRenderer = debugTextView != null
      ? new DebugTrackRenderer(debugTextView, videoRenderer)
      : null;

  // Invoke the callback.
  TrackRenderer[] renderers = new TrackRenderer[DemoPlayer.RENDERER_COUNT];
  renderers[DemoPlayer.TYPE_VIDEO] = videoRenderer;
  renderers[DemoPlayer.TYPE_AUDIO] = audioRenderer;
  renderers[DemoPlayer.TYPE_DEBUG] = debugRenderer;
  callback.onRenderers(null, null, renderers);
}
 
Example #25
Source File: DemoPlayer.java    From androidtv-sample-inputs with Apache License 2.0 6 votes vote down vote up
/**
   * Invoked with the results from a {@link RendererBuilder}.
   *
   * @param renderers      Renderers indexed by {@link DemoPlayer} TYPE_* constants. An individual
   *                       element may be null if there do not exist tracks of the corresponding
   *                       type.
   * @param bandwidthMeter Provides an estimate of the currently available bandwidth. May be
   *                       null.
   */
/* package */ void onRenderers(TrackRenderer[] renderers, BandwidthMeter bandwidthMeter) {
      for (int i = 0; i < RENDERER_COUNT; i++) {
          if (renderers[i] == null) {
              // Convert a null renderer to a dummy renderer.
              renderers[i] = new DummyTrackRenderer();
          }
      }
      // Complete preparation.
      this.videoRenderer = renderers[TYPE_VIDEO];
      this.audioRenderer = renderers[TYPE_AUDIO];
      this.codecCounters = videoRenderer instanceof MediaCodecTrackRenderer
              ? ((MediaCodecTrackRenderer) videoRenderer).codecCounters
              : renderers[TYPE_AUDIO] instanceof MediaCodecTrackRenderer
              ? ((MediaCodecTrackRenderer) renderers[TYPE_AUDIO]).codecCounters : null;
      this.bandwidthMeter = bandwidthMeter;
      pushSurface(false);
      player.prepare(renderers);
      rendererBuildingState = RENDERER_BUILDING_STATE_BUILT;
  }
 
Example #26
Source File: ExoplayerWrapper.java    From google-media-framework-android with Apache License 2.0 6 votes vote down vote up
/**
 * Invoked with the results from a {@link RendererBuilder}.
 *
 * @param renderers Renderers indexed by {@link ExoplayerWrapper} TYPE_* constants. An
 *                  individual element may be null if there do not exist tracks of the
 *                  corresponding type.
 * @param bandwidthMeter Provides an estimate of the currently available bandwidth. May be null.
 */
public void onRenderers(TrackRenderer[] renderers,  BandwidthMeter bandwidthMeter) {
  // Normalize the results.
  if (trackNames == null) {
    trackNames = new String[RENDERER_COUNT][];
  }

  for (int i = 0; i < RENDERER_COUNT; i++) {
    if (renderers[i] == null) {
      // Convert a null renderer to a dummy renderer.
      renderers[i] = new DummyTrackRenderer();
    }
  }

  // Complete preparation.
  this.videoRenderer = renderers[TYPE_VIDEO];
  this.codecCounters = videoRenderer instanceof MediaCodecTrackRenderer
          ? ((MediaCodecTrackRenderer) videoRenderer).codecCounters
          : renderers[TYPE_AUDIO] instanceof MediaCodecTrackRenderer
          ? ((MediaCodecTrackRenderer) renderers[TYPE_AUDIO]).codecCounters : null;
  rendererBuildingState = RENDERER_BUILDING_STATE_BUILT;
  this.bandwidthMeter = bandwidthMeter;
  maybeReportPlayerState();
  pushSurfaceAndVideoTrack(false);
  player.prepare(renderers);
}
 
Example #27
Source File: DemoPlayer.java    From AndroidTvDemo with Apache License 2.0 6 votes vote down vote up
/**
 * Invoked with the results from a {link RendererBuilder}.
 *
 * @param renderers Renderers indexed by {link DemoPlayer} TYPE_* constants. An individual
 *     element may be null if there do not exist tracks of the corresponding type.
 * @param bandwidthMeter Provides an estimate of the currently available bandwidth. May be null.
 */
/* package */ void onRenderers(TrackRenderer[] renderers, BandwidthMeter bandwidthMeter) {
  for (int i = 0; i < RENDERER_COUNT; i++) {
    if (renderers[i] == null) {
      // Convert a null renderer to a dummy renderer.
      renderers[i] = new DummyTrackRenderer();
    }
  }
  // Complete preparation.
  this.videoRenderer = renderers[TYPE_VIDEO];
  this.codecCounters = videoRenderer instanceof MediaCodecTrackRenderer
      ? ((MediaCodecTrackRenderer) videoRenderer).codecCounters
      : renderers[TYPE_AUDIO] instanceof MediaCodecTrackRenderer
      ? ((MediaCodecTrackRenderer) renderers[TYPE_AUDIO]).codecCounters : null;
  this.bandwidthMeter = bandwidthMeter;
  pushSurface(false);
  player.prepare(renderers);
  rendererBuildingState = RENDERER_BUILDING_STATE_BUILT;
}
 
Example #28
Source File: VLCRendererBuilder.java    From Exoplayer_VLC with Apache License 2.0 5 votes vote down vote up
@Override
public void buildRenderers(DemoPlayer player, RendererBuilderCallback callback) {
    TrackRenderer[] renderers = new TrackRenderer[DemoPlayer.RENDERER_COUNT];
    try {
        VLCSampleExtractor extractor = new VLCSampleExtractor(vlc, uri);
        VLCSampleSource vlcsource = new VLCSampleSource(extractor);

        MySurfaceLayoutHandler msh = null;
        System.out.println("VLCRendererBuilder.buildRenderers() props = "+props);
        Object v = props.get(SURFACE_VIEW_RES_ID_PROP);

        if (v instanceof Integer)
            msh = new MySurfaceLayoutHandler(this.context, ((Integer) v).intValue());

        if (msh == null)
            callback.onRenderersError(new ExoPlaybackException("property " + SURFACE_VIEW_RES_ID_PROP + " not set"));


        VLCVideoSurfaceHandler ivdoplayer = new VLCVideoSurfaceHandler( extractor.getLibVLC(),
                player.getMainHandler(), player, msh);

        renderers[DemoPlayer.TYPE_VIDEO] = new VLCVideoTrackRenderer(vlcsource, player.getMainHandler(), player,
                ivdoplayer, extractor.getLibVLC());
        renderers[DemoPlayer.TYPE_AUDIO] = new VLCAudioTrackRenderer(vlcsource, player.getMainHandler(), player,
                extractor.getLibVLC());
    } catch (ExoPlaybackException e) {
        e.printStackTrace();
    }
    callback.onRenderers(null, null, renderers);
}
 
Example #29
Source File: HlsSampleSource.java    From Exoplayer_VLC with Apache License 2.0 5 votes vote down vote up
@Override
public long getBufferedPositionUs() {
  Assertions.checkState(prepared);
  Assertions.checkState(enabledTrackCount > 0);
  if (isPendingReset()) {
    return pendingResetPositionUs;
  } else if (loadingFinished) {
    return TrackRenderer.END_OF_TRACK_US;
  } else {
    long largestSampleTimestamp = extractors.getLast().getLargestSampleTimestamp();
    return largestSampleTimestamp == Long.MIN_VALUE ? downstreamPositionUs
        : largestSampleTimestamp;
  }
}
 
Example #30
Source File: UdpRtpRendererBuilder.java    From Exoplayer_VLC with Apache License 2.0 5 votes vote down vote up
@Override
public void buildRenderers(DemoPlayer player, DemoPlayer.RendererBuilderCallback callback) {

    // Build the video and audio renderers.
    Log.d(TAG, "buildRenderers(): uri=" + uri.toString());

    Handler mainHandler = player.getMainHandler();

    RawExtractor extractor = null;
    BufferPool bufferPool = new BufferPool(this.BUFFER_POOL_LENGTH);
    extractor = new TsExtractor(false, 0, bufferPool);

    DataSource videoDataSource = new UdpMulticastDataSource();
    DataSource rawSource = new RtpSampleSource(videoDataSource);
    SampleSource sampleSource = new RawSampleSource(rawSource, this.uri, this.context, extractor);
    MediaCodecVideoTrackRenderer videoRenderer = new MediaCodecVideoTrackRenderer(sampleSource, null, true, MediaCodec.VIDEO_SCALING_MODE_SCALE_TO_FIT, 5000, null, mainHandler, player, 50);
    MediaCodecAudioTrackRenderer audioRenderer = new MediaCodecAudioTrackRenderer(sampleSource);

    // Build the debug renderer.
    TrackRenderer debugRenderer = debugTextView != null
            ? new DebugTrackRenderer(debugTextView, videoRenderer)
            : null;

    // Invoke the callback.
    TrackRenderer[] renderers = new TrackRenderer[DemoPlayer.RENDERER_COUNT];
    renderers[DemoPlayer.TYPE_VIDEO] = videoRenderer;
    renderers[DemoPlayer.TYPE_AUDIO] = audioRenderer;
    renderers[DemoPlayer.TYPE_DEBUG] = debugRenderer;
    callback.onRenderers(null, null, renderers);
}