com.google.android.exoplayer2.Renderer Java Examples

The following examples show how to use com.google.android.exoplayer2.Renderer. 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: Util.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
/**
 * Extract renderer capabilities for the renderers created by the provided renderers factory.
 *
 * @param renderersFactory A {@link RenderersFactory}.
 * @param drmSessionManager An optional {@link DrmSessionManager} used by the renderers.
 * @return The {@link RendererCapabilities} for each renderer created by the {@code
 *     renderersFactory}.
 */
public static RendererCapabilities[] getRendererCapabilities(
    RenderersFactory renderersFactory,
    @Nullable DrmSessionManager<FrameworkMediaCrypto> drmSessionManager) {
  Renderer[] renderers =
      renderersFactory.createRenderers(
          new Handler(),
          new VideoRendererEventListener() {},
          new AudioRendererEventListener() {},
          (cues) -> {},
          (metadata) -> {},
          drmSessionManager);
  RendererCapabilities[] capabilities = new RendererCapabilities[renderers.length];
  for (int i = 0; i < renderers.length; i++) {
    capabilities[i] = renderers[i].getCapabilities();
  }
  return capabilities;
}
 
Example #2
Source File: RendererProvider.java    From ExoMedia with Apache License 2.0 6 votes vote down vote up
@NonNull
protected List<Renderer> buildVideoRenderers() {
    List<Renderer> renderers = new ArrayList<>();

    renderers.add(new MediaCodecVideoRenderer(context, MediaCodecSelector.DEFAULT, videoJoiningTimeMs, drmSessionManager, false, handler, videoRendererEventListener, droppedFrameNotificationAmount));

    // Adds any registered classes
    List<String> classNames = ExoMedia.Data.registeredRendererClasses.get(ExoMedia.RendererType.VIDEO);
    if (classNames != null) {
        for (String className: classNames) {
            try {
                Class<?> clazz = Class.forName(className);
                Constructor<?> constructor = clazz.getConstructor(boolean.class, long.class, Handler.class, VideoRendererEventListener.class, int.class);
                Renderer renderer = (Renderer) constructor.newInstance(true, videoJoiningTimeMs, handler, videoRendererEventListener, droppedFrameNotificationAmount);
                renderers.add(renderer);
            } catch (Exception e) {
                // Purposefully left blank
            }
        }
    }

    return renderers;
}
 
Example #3
Source File: RendererProvider.java    From ExoMedia with Apache License 2.0 6 votes vote down vote up
@NonNull
protected List<Renderer> buildAudioRenderers() {
    List<Renderer> renderers = new ArrayList<>();
    renderers.add(new MediaCodecAudioRenderer(context, MediaCodecSelector.DEFAULT, drmSessionManager, true, handler, audioRendererEventListener, AudioCapabilities.getCapabilities(context)));

    // Adds any registered classes
    List<String> classNames = ExoMedia.Data.registeredRendererClasses.get(ExoMedia.RendererType.AUDIO);
    if (classNames != null) {
        for (String className: classNames) {
            try {
                Class<?> clazz = Class.forName(className);
                Constructor<?> constructor = clazz.getConstructor(Handler.class, AudioRendererEventListener.class);
                Renderer renderer = (Renderer) constructor.newInstance(handler, audioRendererEventListener);
                renderers.add(renderer);
            } catch (Exception e) {
                // Purposefully left blank
            }
        }
    }

    return renderers;
}
 
Example #4
Source File: ExoMediaPlayer.java    From ExoMedia with Apache License 2.0 6 votes vote down vote up
public ExoMediaPlayer(@NonNull Context context) {
    this.context = context;

    bufferRepeater.setRepeaterDelay(BUFFER_REPEAT_DELAY);
    bufferRepeater.setRepeatListener(new BufferRepeatListener());

    mainHandler = new Handler();

    ComponentListener componentListener = new ComponentListener();
    RendererProvider rendererProvider = new RendererProvider(context, mainHandler, componentListener, componentListener, componentListener, componentListener);
    DrmSessionManager<FrameworkMediaCrypto> drmSessionManager = generateDrmSessionManager();
    rendererProvider.setDrmSessionManager(drmSessionManager);

    renderers = rendererProvider.generate();

    adaptiveTrackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter);
    trackSelector = new DefaultTrackSelector(adaptiveTrackSelectionFactory);

    LoadControl loadControl = ExoMedia.Data.loadControl != null ? ExoMedia.Data.loadControl : new DefaultLoadControl();
    player = ExoPlayerFactory.newInstance(renderers.toArray(new Renderer[renderers.size()]), trackSelector, loadControl);
    player.addListener(this);
    analyticsCollector = new AnalyticsCollector.Factory().createAnalyticsCollector(player, Clock.DEFAULT);
    player.addListener(analyticsCollector);
    setupDamSessionManagerAnalytics(drmSessionManager);
}
 
Example #5
Source File: ExoMediaPlayer.java    From ExoMedia with Apache License 2.0 6 votes vote down vote up
protected void sendMessage(int renderType, int messageType, Object message, boolean blocking) {
    if (renderers.isEmpty()) {
        return;
    }

    List<PlayerMessage> messages = new ArrayList<>();
    for (Renderer renderer : renderers) {
        if (renderer.getTrackType() == renderType) {
            messages.add(player.createMessage(renderer).setType(messageType).setPayload(message));
        }
    }

    if (blocking) {
        blockingSendMessages(messages);
    } else {
        for (PlayerMessage playerMessage : messages) {
            playerMessage.send();
        }
    }
}
 
Example #6
Source File: SimpleRenderersFactory.java    From no-player with Apache License 2.0 6 votes vote down vote up
@Override
public Renderer[] createRenderers(Handler eventHandler,
                                  VideoRendererEventListener videoRendererEventListener,
                                  AudioRendererEventListener audioRendererEventListener,
                                  TextOutput textRendererOutput,
                                  MetadataOutput metadataRendererOutput,
                                  @Nullable DrmSessionManager<FrameworkMediaCrypto> drmSessionManager) {
    ArrayList<Renderer> renderersList = new ArrayList<>();
    buildVideoRenderers(context, drmSessionManager, allowedVideoJoiningTimeMs,
            eventHandler, videoRendererEventListener, extensionRendererMode, renderersList);
    buildAudioRenderers(context, drmSessionManager, buildAudioProcessors(),
            eventHandler, audioRendererEventListener, extensionRendererMode, renderersList);
    buildTextRenderers(textRendererOutput, eventHandler.getLooper(), renderersList, subtitleDecoderFactory);
    buildMetadataRenderers(metadataRendererOutput, eventHandler.getLooper(),
            renderersList);
    buildMiscellaneousRenderers();
    return renderersList.toArray(new Renderer[renderersList.size()]);
}
 
Example #7
Source File: ExoplayerAudioRenderer.java    From lbry-android with MIT License 6 votes vote down vote up
@Override
protected void buildAudioRenderers(
        Context context,
        int extensionRendererMode,
        MediaCodecSelector mediaCodecSelector,
        @Nullable DrmSessionManager<FrameworkMediaCrypto> drmSessionManager,
        boolean playClearSamplesWithoutKeys,
        boolean enableDecoderFallback,
        AudioProcessor[] audioProcessors,
        Handler eventHandler,
        AudioRendererEventListener eventListener,
        ArrayList<Renderer> out) {
    AudioProcessor[] audioProcessorList = { new TeeAudioProcessor(audioBufferSink) };
    super.buildAudioRenderers(
            context,
            extensionRendererMode,
            mediaCodecSelector,
            drmSessionManager,
            playClearSamplesWithoutKeys,
            enableDecoderFallback,
            audioProcessorList,
            eventHandler,
            eventListener,
            out);
}
 
Example #8
Source File: ExoFFmpegPlayer.java    From DanDanPlayForAndroid with MIT License 6 votes vote down vote up
private void onPlayReleased() {

        List<PlayerMessage> messages = new ArrayList<>();

        for (Renderer renderer : renderers) {
            messages.add(createMessage(renderer).setType(MSG_PLAY_RELEASED).send());
        }

        try {
            for (PlayerMessage message : messages){
                message.blockUntilDelivered();
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
 
Example #9
Source File: ExoFFmpegPlayer.java    From DanDanPlayForAndroid with MIT License 6 votes vote down vote up
private void onSurfaceSizeChanged(int width, int height) {
    List<PlayerMessage> messages = new ArrayList<>();
    Point size = new Point(width, height);

    for (Renderer renderer : renderers) {
        if (renderer.getTrackType() == C.TRACK_TYPE_VIDEO) {
            messages.add(createMessage(renderer).setType(Constant.MSG_SURFACE_SIZE_CHANGED).setPayload(size).send());
        }
    }

    try {
        for (PlayerMessage message : messages){
            message.blockUntilDelivered();
        }
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}
 
Example #10
Source File: Util.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Extract renderer capabilities for the renderers created by the provided renderers factory.
 *
 * @param renderersFactory A {@link RenderersFactory}.
 * @param drmSessionManager An optional {@link DrmSessionManager} used by the renderers.
 * @return The {@link RendererCapabilities} for each renderer created by the {@code
 *     renderersFactory}.
 */
public static RendererCapabilities[] getRendererCapabilities(
    RenderersFactory renderersFactory,
    @Nullable DrmSessionManager<FrameworkMediaCrypto> drmSessionManager) {
  Renderer[] renderers =
      renderersFactory.createRenderers(
          new Handler(),
          new VideoRendererEventListener() {},
          new AudioRendererEventListener() {},
          (cues) -> {},
          (metadata) -> {},
          drmSessionManager);
  RendererCapabilities[] capabilities = new RendererCapabilities[renderers.length];
  for (int i = 0; i < renderers.length; i++) {
    capabilities[i] = renderers[i].getCapabilities();
  }
  return capabilities;
}
 
Example #11
Source File: Util.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Extract renderer capabilities for the renderers created by the provided renderers factory.
 *
 * @param renderersFactory A {@link RenderersFactory}.
 * @param drmSessionManager An optional {@link DrmSessionManager} used by the renderers.
 * @return The {@link RendererCapabilities} for each renderer created by the {@code
 *     renderersFactory}.
 */
public static RendererCapabilities[] getRendererCapabilities(
    RenderersFactory renderersFactory,
    @Nullable DrmSessionManager<FrameworkMediaCrypto> drmSessionManager) {
  Renderer[] renderers =
      renderersFactory.createRenderers(
          new Handler(),
          new VideoRendererEventListener() {},
          new AudioRendererEventListener() {},
          (cues) -> {},
          (metadata) -> {},
          drmSessionManager);
  RendererCapabilities[] capabilities = new RendererCapabilities[renderers.length];
  for (int i = 0; i < renderers.length; i++) {
    capabilities[i] = renderers[i].getCapabilities();
  }
  return capabilities;
}
 
Example #12
Source File: DebugSimpleExoPlayer.java    From ExoPlayer-Offline with Apache License 2.0 5 votes vote down vote up
@Override
protected void buildVideoRenderers(Context context, Handler mainHandler,
    DrmSessionManager<FrameworkMediaCrypto> drmSessionManager,
    @ExtensionRendererMode int extensionRendererMode, VideoRendererEventListener eventListener,
    long allowedVideoJoiningTimeMs, ArrayList<Renderer> out) {
  out.add(new DebugMediaCodecVideoRenderer(context, MediaCodecSelector.DEFAULT,
      allowedVideoJoiningTimeMs, mainHandler, drmSessionManager, eventListener,
      MAX_DROPPED_VIDEO_FRAME_COUNT_TO_NOTIFY));
}
 
Example #13
Source File: SimpleRendersFactory.java    From DanDanPlayForAndroid with MIT License 5 votes vote down vote up
@Override
protected void buildVideoRenderers(Context context, int extensionRendererMode, MediaCodecSelector mediaCodecSelector, @Nullable DrmSessionManager<FrameworkMediaCrypto> drmSessionManager, boolean playClearSamplesWithoutKeys, Handler eventHandler, VideoRendererEventListener eventListener, long allowedVideoJoiningTimeMs, ArrayList<Renderer> out) {
    BaseRenderer ffmpegRenderer = new SoftVideoRenderer(true,
            allowedVideoJoiningTimeMs, eventHandler, eventListener,
            MAX_DROPPED_VIDEO_FRAME_COUNT_TO_NOTIFY,
            drmSessionManager, false);
    out.add(ffmpegRenderer);
    super.buildVideoRenderers(context, extensionRendererMode, mediaCodecSelector, drmSessionManager, playClearSamplesWithoutKeys, eventHandler, eventListener, allowedVideoJoiningTimeMs, out);
}
 
Example #14
Source File: RendererProvider.java    From ExoMedia with Apache License 2.0 5 votes vote down vote up
@NonNull
public List<Renderer> generate() {
    List<Renderer> renderers = new ArrayList<>();

    renderers.addAll(buildAudioRenderers());
    renderers.addAll(buildVideoRenderers());
    renderers.addAll(buildCaptionRenderers());
    renderers.addAll(buildMetadataRenderers());

    return renderers;
}
 
Example #15
Source File: RendererProvider.java    From ExoMedia with Apache License 2.0 5 votes vote down vote up
@NonNull
protected List<Renderer> buildCaptionRenderers() {
    List<Renderer> renderers = new ArrayList<>();

    renderers.add(new TextRenderer(captionListener, handler.getLooper()));

    return renderers;
}
 
Example #16
Source File: RendererProvider.java    From ExoMedia with Apache License 2.0 5 votes vote down vote up
@NonNull
protected List<Renderer> buildMetadataRenderers() {
    List<Renderer> renderers = new ArrayList<>();

    renderers.add(new MetadataRenderer(metadataListener, handler.getLooper(), MetadataDecoderFactory.DEFAULT));

    return renderers;
}
 
Example #17
Source File: VideoPlayer.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected void buildAudioRenderers(Context context, int extensionRendererMode, MediaCodecSelector mediaCodecSelector, @Nullable DrmSessionManager<FrameworkMediaCrypto> drmSessionManager, boolean playClearSamplesWithoutKeys, boolean enableDecoderFallback, AudioProcessor[] audioProcessors, Handler eventHandler, AudioRendererEventListener eventListener, ArrayList<Renderer> out) {
    AudioProcessor audioProcessor = new TeeAudioProcessor(new VisualizerBufferSink());
    super.buildAudioRenderers(context, extensionRendererMode, mediaCodecSelector, drmSessionManager, playClearSamplesWithoutKeys, enableDecoderFallback, new AudioProcessor[]{audioProcessor}, eventHandler, eventListener, out);
}
 
Example #18
Source File: VideoPlayer.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected void buildAudioRenderers(Context context, int extensionRendererMode, MediaCodecSelector mediaCodecSelector, @Nullable DrmSessionManager<FrameworkMediaCrypto> drmSessionManager, boolean playClearSamplesWithoutKeys, boolean enableDecoderFallback, AudioProcessor[] audioProcessors, Handler eventHandler, AudioRendererEventListener eventListener, ArrayList<Renderer> out) {
    AudioProcessor audioProcessor = new TeeAudioProcessor(new VisualizerBufferSink());
    super.buildAudioRenderers(context, extensionRendererMode, mediaCodecSelector, drmSessionManager, playClearSamplesWithoutKeys, enableDecoderFallback, new AudioProcessor[]{audioProcessor}, eventHandler, eventListener, out);
}
 
Example #19
Source File: MultiDrmRendererFactory.java    From ARVI with Apache License 2.0 4 votes vote down vote up
@Override
protected void buildVideoRenderers(Context context,
                                   int extensionRendererMode,
                                   MediaCodecSelector mediaCodecSelector,
                                   @Nullable DrmSessionManager<FrameworkMediaCrypto> drmSessionManager,
                                   boolean playClearSamplesWithoutKeys,
                                   boolean enableDecoderFallback,
                                   Handler eventHandler,
                                   VideoRendererEventListener eventListener,
                                   long allowedVideoJoiningTimeMs,
                                   ArrayList<Renderer> out) {
    final ArrayList<Renderer> localOut = new ArrayList<>();

    super.buildVideoRenderers(
        context,
        extensionRendererMode,
        mediaCodecSelector,
        drmSessionManager,
        playClearSamplesWithoutKeys,
        enableDecoderFallback,
        eventHandler,
        eventListener,
        allowedVideoJoiningTimeMs,
        localOut
    );

    final Set<Renderer> outSet = new HashSet<>(localOut);

    if(!this.drmSessionManagers.isEmpty()) {
        localOut.clear();

        for(DrmSessionManager<FrameworkMediaCrypto> manager : this.drmSessionManagers) {
            super.buildVideoRenderers(
                context,
                EXTENSION_RENDERER_MODE_OFF,
                mediaCodecSelector,
                manager,
                playClearSamplesWithoutKeys,
                enableDecoderFallback,
                eventHandler,
                eventListener,
                allowedVideoJoiningTimeMs,
                localOut
            );
        }

        outSet.addAll(localOut);
    }

    out.addAll(outSet);
}
 
Example #20
Source File: SimpleRendersFactory.java    From DanDanPlayForAndroid with MIT License 4 votes vote down vote up
@Override
protected void buildAudioRenderers(Context context, int extensionRendererMode, MediaCodecSelector mediaCodecSelector, @Nullable DrmSessionManager<FrameworkMediaCrypto> drmSessionManager, boolean playClearSamplesWithoutKeys, AudioProcessor[] audioProcessors, Handler eventHandler, AudioRendererEventListener eventListener, ArrayList<Renderer> out) {
    out.add(new SoftAudioRenderer());
    super.buildAudioRenderers(context, extensionRendererMode, mediaCodecSelector, drmSessionManager, playClearSamplesWithoutKeys, audioProcessors, eventHandler, eventListener, out);
}
 
Example #21
Source File: VideoManager.java    From jellyfin-androidtv with GNU General Public License v2.0 4 votes vote down vote up
public VideoManager(PlaybackOverlayActivity activity, View view) {
    mActivity = activity;
    mSurfaceView = view.findViewById(R.id.player_surface);
    mSurfaceHolder = mSurfaceView.getHolder();
    mSurfaceHolder.addCallback(mSurfaceCallback);
    mSurfaceFrame = view.findViewById(R.id.player_surface_frame);
    mSubtitlesSurface = view.findViewById(R.id.subtitles_surface);
    if (DeviceUtils.is50()) {
        mSubtitlesSurface.setZOrderMediaOverlay(true);
        mSubtitlesSurface.getHolder().setFormat(PixelFormat.TRANSLUCENT);
        hasSubtitlesSurface = true;
    } else {
        mSubtitlesSurface.setVisibility(View.GONE);
    }

    mExoPlayer = new SimpleExoPlayer.Builder(TvApp.getApplication(), new DefaultRenderersFactory(TvApp.getApplication()) {
        @Override
        protected void buildTextRenderers(Context context, TextOutput output, Looper outputLooper, int extensionRendererMode, ArrayList<Renderer> out) {
            // Do not add text renderers since we handle subtitles
        }
    }).build();

    mExoPlayerView = view.findViewById(R.id.exoPlayerView);
    mExoPlayerView.setPlayer(mExoPlayer);
    mExoPlayer.addListener(new Player.EventListener() {
        @Override
        public void onPlayerError(ExoPlaybackException error) {
            Timber.e("***** Got error from player");
            if (errorListener != null) errorListener.onEvent();
            stopProgressLoop();
        }

        @Override
        public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
            // Do not call listener when paused
            if (playbackState == Player.STATE_READY && playWhenReady) {
                if (preparedListener != null) preparedListener.onEvent();
                startProgressLoop();
            } else if (playbackState == Player.STATE_ENDED) {
                if (completionListener != null) completionListener.onEvent();
                stopProgressLoop();
            }
        }
    });
}
 
Example #22
Source File: MultiDrmRendererFactory.java    From ARVI with Apache License 2.0 4 votes vote down vote up
@Override
protected void buildAudioRenderers(Context context,
                                   int extensionRendererMode,
                                   MediaCodecSelector mediaCodecSelector,
                                   @Nullable DrmSessionManager<FrameworkMediaCrypto> drmSessionManager,
                                   boolean playClearSamplesWithoutKeys,
                                   boolean enableDecoderFallback,
                                   AudioProcessor[] audioProcessors,
                                   Handler eventHandler,
                                   AudioRendererEventListener eventListener,
                                   ArrayList<Renderer> out) {
    final ArrayList<Renderer> localOut = new ArrayList<>();

    super.buildAudioRenderers(
        context,
        extensionRendererMode,
        mediaCodecSelector,
        drmSessionManager,
        playClearSamplesWithoutKeys,
        enableDecoderFallback,
        audioProcessors,
        eventHandler,
        eventListener,
        localOut
    );

    final Set<Renderer> outSet = new HashSet<>(localOut);

    if(!this.drmSessionManagers.isEmpty()) {
        localOut.clear();

        for(DrmSessionManager<FrameworkMediaCrypto> manager : this.drmSessionManagers) {
            super.buildAudioRenderers(
                context,
                EXTENSION_RENDERER_MODE_OFF,
                mediaCodecSelector,
                manager,
                playClearSamplesWithoutKeys,
                enableDecoderFallback,
                audioProcessors,
                eventHandler,
                eventListener,
                localOut
            );
        }

        outSet.addAll(localOut);
    }

    out.addAll(outSet);
}
 
Example #23
Source File: ExoMedia.java    From ExoMedia with Apache License 2.0 2 votes vote down vote up
/**
 * Registers additional customized {@link com.google.android.exoplayer2.Renderer}s
 * that will be used by the {@link com.google.android.exoplayer2.source.MediaSource}s to
 * correctly play media.
 *
 * @param type The type for the renderer
 * @param clazz The class of the customized Renderer
 */
public static void registerRenderer(@NonNull RendererType type, @NonNull Class<? extends Renderer> clazz) {
    Data.registeredRendererClasses.get(type).add(clazz.getName());
}
 
Example #24
Source File: SimpleRenderersFactory.java    From no-player with Apache License 2.0 2 votes vote down vote up
/**
 * Builds metadata renderers for use by the player.
 *
 * @param output       An output for the renderers.
 * @param outputLooper The looper associated with the thread on which the output should be
 *                     called.
 * @param outRenderers An array to which the built renderers should be appended.
 */
private void buildMetadataRenderers(MetadataOutput output, Looper outputLooper, List<Renderer> outRenderers) {
    outRenderers.add(new MetadataRenderer(output, outputLooper));
}
 
Example #25
Source File: SimpleRenderersFactory.java    From no-player with Apache License 2.0 2 votes vote down vote up
/**
 * Builds text renderers for use by the player.
 *  @param output       An output for the renderers.
 * @param outputLooper The looper associated with the thread on which the output should be
 *                     called.
 * @param outRenderers An array to which the built renderers should be appended.
 * @param decoderFactory A factory from which to obtain {@link SubtitleDecoder} instances.
 */
private void buildTextRenderers(TextOutput output, Looper outputLooper, List<Renderer> outRenderers, SubtitleDecoderFactory decoderFactory) {
    outRenderers.add(new TextRenderer(output, outputLooper, decoderFactory));
}