com.google.android.exoplayer.MediaCodecAudioTrackRenderer Java Examples

The following examples show how to use com.google.android.exoplayer.MediaCodecAudioTrackRenderer. 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: 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 #2
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 #3
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 #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: 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 #6
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 #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: 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 #9
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 #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: 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 #12
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 #13
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 #14
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 #15
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 #16
Source File: VLCAudioTrackRenderer.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.MediaCodecAudioTrackRenderer.MSG_SET_VOLUME) {
		/* the volume in percents (0 = mute, 100 = 0dB) */
		int v = com.exovlc.ExoVlcUtil.media2vlcVolume((Float) message);
		if (vlc.setVolume(v) == -1)
			ExoVlcUtil.log(this, "Err when setting VLC audio level :" + v);
		;
	} else {
		super.handleMessage(messageType, message);
	}
}
 
Example #17
Source File: VLCAudioTrackRenderer.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.MediaCodecAudioTrackRenderer.MSG_SET_VOLUME) {
		/* the volume in percents (0 = mute, 100 = 0dB) */
		int v = com.exovlc.ExoVlcUtil.media2vlcVolume((Float) message);
		if (vlc.setVolume(v) == -1)
			ExoVlcUtil.log(this, "Err when setting VLC audio level :" + v);
		;
	} else {
		super.handleMessage(messageType, message);
	}
}
 
Example #18
Source File: DemoPlayer.java    From Mobilyzer with Apache License 2.0 5 votes vote down vote up
void onRenderers(String[][] trackNames,
    MultiTrackChunkSource[] multiTrackSources, TrackRenderer[] renderers) {
  builderCallback = null;
  // Normalize the results.
  if (trackNames == null) {
    trackNames = new String[RENDERER_COUNT][];
  }
  if (multiTrackSources == null) {
    multiTrackSources = new MultiTrackChunkSource[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();
    } else if (trackNames[i] == null) {
      // We have a renderer so we must have at least one track, but the names are unknown.
      // Initialize the correct number of null track names.
      int trackCount = multiTrackSources[i] == null ? 1 : multiTrackSources[i].getTrackCount();
      trackNames[i] = new String[trackCount];
    }
  }
  // Complete preparation.
  this.videoRenderer = renderers[TYPE_VIDEO];
  this.trackNames = trackNames;
  this.multiTrackSources = multiTrackSources;
  rendererBuildingState = RENDERER_BUILDING_STATE_BUILT;
  maybeReportPlayerState();
  pushSurfaceAndVideoTrack(false);
  pushTrackSelection(TYPE_AUDIO, true);
  pushTrackSelection(TYPE_TEXT, true);
  player.prepare(renderers);
  // silent the player
  player.sendMessage(renderers[TYPE_AUDIO], MediaCodecAudioTrackRenderer.MSG_SET_VOLUME, (float) 0.0);
}
 
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: UdpMulticastRendererBuilder.java    From Exoplayer_VLC with Apache License 2.0 5 votes vote down vote up
@Override
public void buildRenderers(DemoPlayer player, DemoPlayer.RendererBuilderCallback callback) {
    Log.d(TAG, "******************buildRenderers(): uri=" + uri.toString());

    DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
    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 UdpSampleSource(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);

    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());


    // 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_TIMED_METADATA] = id3Renderer;
    renderers[DemoPlayer.TYPE_TEXT] = closedCaptionRenderer;

    renderers[DemoPlayer.TYPE_DEBUG] = debugRenderer;
    callback.onRenderers(null, null, renderers);
}
 
Example #21
Source File: TvInputPlayer.java    From ChannelSurfer with MIT License 5 votes vote down vote up
public void setVolume(float volume) {
    mVolume = volume;
    if (mPlayer != null && audioRenderer != null) {
        mPlayer.sendMessage(audioRenderer, MediaCodecAudioTrackRenderer.MSG_SET_VOLUME,
                volume);
    }
}
 
Example #22
Source File: RawHttpRendererBuilder.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;
    if( playerType == DemoUtil.TYPE_RAW_HTTP_TS) {
        BufferPool bufferPool = new BufferPool(this.BUFFER_POOL_LENGTH);
        extractor = new TsExtractor(false, 0, bufferPool);
    }

    DataSource videoDataSource = new RawHttpDataSource(userAgent, RawHttpDataSource.REJECT_PAYWALL_TYPES);
    DataSource rawSource = new RawBufferedSource(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; // audioRenderer;
    renderers[DemoPlayer.TYPE_DEBUG] = debugRenderer;
    callback.onRenderers(null, null, renderers);
}
 
Example #23
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 #24
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 #25
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 #26
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 #27
Source File: PlayerActivity.java    From android-tv-leanback with Apache License 2.0 5 votes vote down vote up
private void preparePlayer() {
    Log.d(TAG, "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);
    player.prepare(videoRenderer, audioRenderer);
    if (mIsOnTv) {
        // This PlayerControl must stay in sync with PlaybackOverlayFragment.
        // We created methods such as PlaybackOverlayFragment.pressPlay() to request
        // that the fragment change the playback state. When the fragment receives a playback
        // request, it updates the UI and then calls a method in this activity according to
        // PlaybackOverlayFragment.OnPlayPauseClickedListener.
        playerControl = new PlayerControl(player);
    } else {
        // Build the player controls
        mediaController.setMediaPlayer(new PlayerControl(player));
        mediaController.setEnabled(true);
    }
    maybeStartPlayback();
}
 
Example #28
Source File: DemoPlayer.java    From androidtv-sample-inputs with Apache License 2.0 4 votes vote down vote up
@Override
@RequiresApi(api = Build.VERSION_CODES.M)
public void setPlaybackParams(PlaybackParams params) {
    playbackParams = params;
    if (playbackParamsListener == null) {
        playbackParamsListener = new ExoPlayer.Listener() {
            @Override
            public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
            }

            @Override
            public void onPlayWhenReadyCommitted() {
            }

            @Override
            public void onPlayerError(ExoPlaybackException error) {
                // Check if there is an error setting PlaybackParams
                if (error.getCause() instanceof IllegalArgumentException
                        && error.getCause().getStackTrace()[0].getMethodName()
                        .equals("native_set_playback_params")) {
                    // Make sure the error is related to PlaybackParams
                    if (playbackParams != null
                            && Math.abs(playbackParams.getSpeed() - 1f) > 0.1) {
                        if (fakeTrickplayRunnable == null) {
                            fakeTrickplayRunnable = new FakeTrickplayRunnable(DemoPlayer.this);
                        }
                        fakeTrickplayRunnable.setPlaybackParams(playbackParams);
                        prepare();
                        play();
                    }
                }
            }
        };
        player.addListener(playbackParamsListener);
    }

    // Check if our speed is close to or equal to 1
    if (Math.abs(params.getSpeed() - 1f) < 0.1 && fakeTrickplayRunnable != null) {
        // Stop the fake trickplay
        fakeTrickplayRunnable.setPlaybackParams(params);
        prepare();
        play();
    }
    player.sendMessage(audioRenderer, MediaCodecAudioTrackRenderer.MSG_SET_PLAYBACK_PARAMS,
            params);
}
 
Example #29
Source File: DashRendererBuilder.java    From androidtv-sample-inputs with Apache License 2.0 4 votes vote down vote up
private void buildRenderers() {
    Period period = manifest.getPeriod(0);
    Handler mainHandler = player.getMainHandler();
    LoadControl loadControl = new DefaultLoadControl(new DefaultAllocator(
            BUFFER_SEGMENT_SIZE));
    DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(mainHandler, player);

    boolean hasContentProtection = false;
    for (int i = 0; i < period.adaptationSets.size(); i++) {
        AdaptationSet adaptationSet = period.adaptationSets.get(i);
        if (adaptationSet.type != AdaptationSet.TYPE_UNKNOWN) {
            hasContentProtection |= adaptationSet.hasContentProtection();
        }
    }

    // Check drm support if necessary.
    boolean filterHdContent = false;
    StreamingDrmSessionManager drmSessionManager = null;
    if (hasContentProtection) {
        if (Util.SDK_INT < 18) {
            player.onRenderersError(
                    new UnsupportedDrmException(
                            UnsupportedDrmException.REASON_UNSUPPORTED_SCHEME));
            return;
        }
        try {
            drmSessionManager = StreamingDrmSessionManager.newWidevineInstance(
                    player.getPlaybackLooper(), drmCallback, null, player.getMainHandler(),
                    player);
            filterHdContent =
                    getWidevineSecurityLevel(drmSessionManager) != SECURITY_LEVEL_1;
        } catch (UnsupportedDrmException e) {
            player.onRenderersError(e);
            return;
        }
    }

    // Build the video renderer.
    DataSource videoDataSource =
            new DefaultUriDataSource(context, bandwidthMeter, userAgent);
    ChunkSource videoChunkSource = new DashChunkSource(manifestFetcher,
            DefaultDashTrackSelector.newVideoInstance(context, true, filterHdContent),
            videoDataSource, new AdaptiveEvaluator(bandwidthMeter), LIVE_EDGE_LATENCY_MS,
            elapsedRealtimeOffset, mainHandler, player, DemoPlayer.TYPE_VIDEO);
    ChunkSampleSource videoSampleSource =
            new ChunkSampleSource(videoChunkSource, loadControl,
                    VIDEO_BUFFER_SEGMENTS * BUFFER_SEGMENT_SIZE, mainHandler, player,
                    DemoPlayer.TYPE_VIDEO);
    TrackRenderer videoRenderer =
            new MediaCodecVideoTrackRenderer(context, videoSampleSource,
                    MediaCodecSelector.DEFAULT, 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 DashChunkSource(manifestFetcher,
            DefaultDashTrackSelector.newAudioInstance(), audioDataSource, null,
            LIVE_EDGE_LATENCY_MS,
            elapsedRealtimeOffset, mainHandler, player, DemoPlayer.TYPE_AUDIO);
    ChunkSampleSource audioSampleSource =
            new ChunkSampleSource(audioChunkSource, loadControl,
                    AUDIO_BUFFER_SEGMENTS * BUFFER_SEGMENT_SIZE, mainHandler, player,
                    DemoPlayer.TYPE_AUDIO);
    TrackRenderer audioRenderer = new MediaCodecAudioTrackRenderer(audioSampleSource,
            MediaCodecSelector.DEFAULT, drmSessionManager, true, mainHandler, player,
            AudioCapabilities.getCapabilities(context), AudioManager.STREAM_MUSIC);

    // Build the text renderer.
    DataSource textDataSource =
            new DefaultUriDataSource(context, bandwidthMeter, userAgent);
    ChunkSource textChunkSource = new DashChunkSource(manifestFetcher,
            DefaultDashTrackSelector.newTextInstance(), textDataSource, null,
            LIVE_EDGE_LATENCY_MS,
            elapsedRealtimeOffset, mainHandler, player, DemoPlayer.TYPE_TEXT);
    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);
}
 
Example #30
Source File: DemoPlayer.java    From androidtv-sample-inputs with Apache License 2.0 4 votes vote down vote up
public void setVolume(float volume) {
    player.sendMessage(audioRenderer, MediaCodecAudioTrackRenderer.MSG_SET_VOLUME,
            volume);
}