com.google.android.exoplayer.MediaCodecVideoTrackRenderer Java Examples

The following examples show how to use com.google.android.exoplayer.MediaCodecVideoTrackRenderer. 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: PlayerActivity.java    From android-tv-leanback with Apache License 2.0 6 votes vote down vote up
private void maybeStartPlayback() {
    Log.d(TAG, "maybeStartPlayback");
    Surface surface = surfaceView.getHolder().getSurface();
    if (videoRenderer == null || surface == null || !surface.isValid()) {
        // We're not ready yet.
        return;
    }
    player.sendMessage(videoRenderer, MediaCodecVideoTrackRenderer.MSG_SET_SURFACE, surface);
    if (autoPlay) {
        if (mIsOnTv) {
            // This will update the player controls and the activity will receive the callback
            // OnPlayPauseClickedListener.onFragmentPlayPause(Video, int, Boolean)
            mPlaybackOverlayFragment.pressPlay();
        } else {
            player.setPlayWhenReady(true);
        }
        autoPlay = false;
    }
}
 
Example #3
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 #4
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 #5
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 #6
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 #7
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 #8
Source File: TvInputPlayer.java    From ChannelSurfer with MIT License 6 votes vote down vote up
private void prepareInternal(boolean usingLocalMedia) {
        Log.d(TAG, "Prepare internal");
        try {
//            if(!usingLocalMedia) {
                mPlayer.prepare(audioRenderer, videoRenderer, textRenderer);
                mPlayer.sendMessage(audioRenderer, MediaCodecAudioTrackRenderer.MSG_SET_VOLUME,
                        mVolume);
                mPlayer.sendMessage(videoRenderer, MediaCodecVideoTrackRenderer.MSG_SET_SURFACE,
                        mSurface);
                // Disable text track by default.
                //mPlayer.setRendererEnabled(TvTrackInfo.TYPE_SUBTITLE, false);
//            }
            for (Callback callback : mCallbacks) {
                callback.onPrepared();
            }
        } catch(Exception E) {
            Log.e(TAG, E.getMessage() + "<(o.o<)");
            Log.e(TAG, E.getClass().getSimpleName());
            if(E.getClass().getName().contains("ExoPlaybackException")) {
                throw new IllegalArgumentException(E.getMessage()+"");
            }
        }
    }
 
Example #9
Source File: VLCVideoSurfaceHandler.java    From Exoplayer_VLC with Apache License 2.0 6 votes vote down vote up
public VLCVideoSurfaceHandler( LibVLC libvlc, Handler eventHandler,
		MediaCodecVideoTrackRenderer.EventListener eventListener, SurfaceLayoutHandler layoutHandler) throws ExoPlaybackException {
	super();
	this.libvlc = libvlc;
	this.eventHandler = eventHandler;
	this.eventListener = eventListener;

	
	if (layoutHandler != null) {
		this.layoutHandler = layoutHandler;
			SurfaceHolder surfaceHolder = layoutHandler.getHolder();
		ExoVlcUtil.log(this, "VLCIVideoSurfaceHandler.VLCIVideoSurfaceHandler()");
		ExoVlcUtil.log(this, "## ====> rect= " + surfaceHolder.getSurfaceFrame());
		if (com.exovlc.ExoVlcUtil.validSurface(surfaceHolder))
			setVlcSurface(surfaceHolder.getSurface(), false);

	} else
		throw new ExoPlaybackException("layout handler null.");

}
 
Example #10
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 #11
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 #12
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 #13
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 #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: VLCVideoSurfaceHandler.java    From Exoplayer_VLC with Apache License 2.0 6 votes vote down vote up
public VLCVideoSurfaceHandler( LibVLC libvlc, Handler eventHandler,
		MediaCodecVideoTrackRenderer.EventListener eventListener, SurfaceLayoutHandler layoutHandler) throws ExoPlaybackException {
	super();
	this.libvlc = libvlc;
	this.eventHandler = eventHandler;
	this.eventListener = eventListener;

	
	if (layoutHandler != null) {
		this.layoutHandler = layoutHandler;
			SurfaceHolder surfaceHolder = layoutHandler.getHolder();
		ExoVlcUtil.log(this, "VLCIVideoSurfaceHandler.VLCIVideoSurfaceHandler()");
		ExoVlcUtil.log(this, "## ====> rect= " + surfaceHolder.getSurfaceFrame());
		if (com.exovlc.ExoVlcUtil.validSurface(surfaceHolder))
			setVlcSurface(surfaceHolder.getSurface(), false);

	} else
		throw new ExoPlaybackException("layout handler null.");

}
 
Example #17
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 #18
Source File: PlayerActivity.java    From android-tv-leanback with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_player);

    View root = findViewById(R.id.root);
    mediaController = new MediaController(this);

    //overscan safe on 1980 * 1080 TV
    mediaController.setPadding(48, 27, 48, 27);
    mediaController.setAnchorView(root);
    shutterView = findViewById(R.id.shutter);
    surfaceView = (VideoSurfaceView) findViewById(R.id.surface_view);
    surfaceView.getHolder().addCallback(this);

    SampleSource sampleSource =
            new FrameworkSampleSource(this, Uri.parse(url), /* 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 #19
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);
}
 
Example #20
Source File: DemoPlayer.java    From droidkaigi2016 with Apache License 2.0 5 votes vote down vote up
private void pushSurface(boolean blockForSurfacePush) {
  if (videoRenderer == null) {
    return;
  }

  if (blockForSurfacePush) {
    player.blockingSendMessage(
        videoRenderer, MediaCodecVideoTrackRenderer.MSG_SET_SURFACE, surface);
  } else {
    player.sendMessage(
        videoRenderer, MediaCodecVideoTrackRenderer.MSG_SET_SURFACE, surface);
  }
}
 
Example #21
Source File: DemoPlayer.java    From Mobilyzer with Apache License 2.0 5 votes vote down vote up
private void pushSurfaceAndVideoTrack(boolean blockForSurfacePush) {
  if (rendererBuildingState != RENDERER_BUILDING_STATE_BUILT) {
    return;
  }

  if (blockForSurfacePush) {
    player.blockingSendMessage(
        videoRenderer, MediaCodecVideoTrackRenderer.MSG_SET_SURFACE, surface);
  } else {
    player.sendMessage(
        videoRenderer, MediaCodecVideoTrackRenderer.MSG_SET_SURFACE, surface);
  }
  pushTrackSelection(TYPE_VIDEO, surface != null && surface.isValid());
}
 
Example #22
Source File: DemoPlayer.java    From androidtv-sample-inputs with Apache License 2.0 5 votes vote down vote up
private void pushSurface(boolean blockForSurfacePush) {
    if (videoRenderer == null) {
        return;
    }

    if (blockForSurfacePush) {
        player.blockingSendMessage(
                videoRenderer, MediaCodecVideoTrackRenderer.MSG_SET_SURFACE, surface);
    } else {
        player.sendMessage(
                videoRenderer, MediaCodecVideoTrackRenderer.MSG_SET_SURFACE, surface);
    }
}
 
Example #23
Source File: ExtractorRendererBuilder.java    From androidtv-sample-inputs with Apache License 2.0 5 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, 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[DemoPlayer.RENDERER_COUNT];
    renderers[DemoPlayer.TYPE_VIDEO] = videoRenderer;
    renderers[DemoPlayer.TYPE_AUDIO] = audioRenderer;
    renderers[DemoPlayer.TYPE_TEXT] = textRenderer;
    player.onRenderers(renderers, bandwidthMeter);
}
 
Example #24
Source File: ExoplayerWrapper.java    From google-media-framework-android with Apache License 2.0 5 votes vote down vote up
/**
 * Updated the playback thread with the latest video renderer and surface.
 * @param blockForSurfacePush If true, then message sent to the underlying playback thread is
 *                            guaranteed to be delivered. However, this is a blocking operation
 */
private void pushSurfaceAndVideoTrack(boolean blockForSurfacePush) {
  if (rendererBuildingState != RENDERER_BUILDING_STATE_BUILT) {
    return;
  }

  if (blockForSurfacePush) {
    player.blockingSendMessage(
        videoRenderer, MediaCodecVideoTrackRenderer.MSG_SET_SURFACE, surface);
  } else {
    player.sendMessage(
        videoRenderer, MediaCodecVideoTrackRenderer.MSG_SET_SURFACE, surface);
  }
}
 
Example #25
Source File: VLCVideoTrackRenderer.java    From Exoplayer_VLC with Apache License 2.0 5 votes vote down vote up
public void handleMessage(int messageType, Object message) throws ExoPlaybackException {
	if (messageType == com.google.android.exoplayer.MediaCodecVideoTrackRenderer.MSG_SET_SURFACE) {
		ExoVlcUtil.log(this, ">>> VLCVideoTrackRenderer.handleMessage() >>> surface = " + (Surface) message);
		Thread.dumpStack();
		this.surfaceHdl.setVlcSurface((Surface) message, false);
	} else {
		super.handleMessage(messageType, message);
	}
}
 
Example #26
Source File: PlayerActivity.java    From android-tv-leanback with Apache License 2.0 5 votes vote down vote up
private void maybeStartPlayback() {
    Log.d(TAG, "maybeStartPlayback");
    Surface surface = surfaceView.getHolder().getSurface();
    if (videoRenderer == null || surface == null || !surface.isValid()) {
        // We're not ready yet.
        return;
    }
    player.sendMessage(videoRenderer, MediaCodecVideoTrackRenderer.MSG_SET_SURFACE, surface);
    if (autoPlay) {
        player.setPlayWhenReady(true);
        autoPlay = false;
    }
}
 
Example #27
Source File: VideoPlayer.java    From iview-android-tv with MIT License 5 votes vote down vote up
private void pushSurface(boolean blockForSurfacePush) {
    if (videoRenderer == null) {
        return;
    }

    if (blockForSurfacePush) {
        player.blockingSendMessage(
                videoRenderer, MediaCodecVideoTrackRenderer.MSG_SET_SURFACE, surface);
    } else {
        player.sendMessage(
                videoRenderer, MediaCodecVideoTrackRenderer.MSG_SET_SURFACE, surface);
    }
}
 
Example #28
Source File: PlayerActivity.java    From android-tv-leanback with Apache License 2.0 5 votes vote down vote up
private void maybeStartPlayback() {
    Log.d(TAG, "maybeStartPlayback");
    Surface surface = surfaceView.getHolder().getSurface();
    if (videoRenderer == null || surface == null || !surface.isValid()) {
        // We're not ready yet.
        return;
    }
    player.sendMessage(videoRenderer, MediaCodecVideoTrackRenderer.MSG_SET_SURFACE, surface);
    if (autoPlay) {
        player.setPlayWhenReady(true);
        autoPlay = false;
    }
}
 
Example #29
Source File: VideoView.java    From meiShi with Apache License 2.0 5 votes vote down vote up
public void start() {
    SampleSource sampleSource = createSource();
    videoRenderer = new MediaCodecVideoTrackRenderer(getContext(),
            sampleSource, MediaCodecSelector.DEFAULT, MediaCodec.VIDEO_SCALING_MODE_SCALE_TO_FIT, 5000,
            handler, this, 50);
    audioRenderer = new MediaCodecAudioTrackRenderer(sampleSource,
            MediaCodecSelector.DEFAULT, null, true, handler, null,
            AudioCapabilities.getCapabilities(getContext()), AudioManager.STREAM_MUSIC);
    player.prepare(videoRenderer, audioRenderer);
    player.setPlayWhenReady(true);
    if (isAvailable()) {
        player.sendMessage(videoRenderer, MediaCodecVideoTrackRenderer.MSG_SET_SURFACE, new Surface(getSurfaceTexture()));
    }
}
 
Example #30
Source File: Player.java    From exoplayer-textureview with Apache License 2.0 5 votes vote down vote up
private void pushSurface(boolean blockForSurfacePush) {
    if (videoRenderer == null || surface == null) {
        return;
    }
    if (blockForSurfacePush) {
        player.blockingSendMessage(videoRenderer, MediaCodecVideoTrackRenderer.MSG_SET_SURFACE,
                surface);
    } else {
        player.sendMessage(videoRenderer, MediaCodecVideoTrackRenderer.MSG_SET_SURFACE,
                surface);
    }
}