Search in sources :

Example 1 with DebugTextViewHelper

use of com.google.android.exoplayer2.util.DebugTextViewHelper in project ExoPlayer by google.

the class PlayerActivity method initializePlayer.

/**
 * @return Whether initialization was successful.
 */
protected boolean initializePlayer() {
    if (player == null) {
        Intent intent = getIntent();
        mediaItems = createMediaItems(intent);
        if (mediaItems.isEmpty()) {
            return false;
        }
        boolean preferExtensionDecoders = intent.getBooleanExtra(IntentUtil.PREFER_EXTENSION_DECODERS_EXTRA, false);
        RenderersFactory renderersFactory = DemoUtil.buildRenderersFactory(/* context= */
        this, preferExtensionDecoders);
        trackSelector = new DefaultTrackSelector(/* context= */
        this);
        lastSeenTracksInfo = TracksInfo.EMPTY;
        player = new ExoPlayer.Builder(/* context= */
        this).setRenderersFactory(renderersFactory).setMediaSourceFactory(createMediaSourceFactory()).setTrackSelector(trackSelector).build();
        player.setTrackSelectionParameters(trackSelectionParameters);
        player.addListener(new PlayerEventListener());
        player.addAnalyticsListener(new EventLogger(trackSelector));
        player.setAudioAttributes(AudioAttributes.DEFAULT, /* handleAudioFocus= */
        true);
        player.setPlayWhenReady(startAutoPlay);
        playerView.setPlayer(player);
        serverSideAdsLoader.setPlayer(player);
        debugViewHelper = new DebugTextViewHelper(player, debugTextView);
        debugViewHelper.start();
    }
    boolean haveStartPosition = startItemIndex != C.INDEX_UNSET;
    if (haveStartPosition) {
        player.seekTo(startItemIndex, startPosition);
    }
    player.setMediaItems(mediaItems, /* resetPosition= */
    !haveStartPosition);
    player.prepare();
    updateButtonVisibility();
    return true;
}
Also used : DebugTextViewHelper(com.google.android.exoplayer2.util.DebugTextViewHelper) EventLogger(com.google.android.exoplayer2.util.EventLogger) DefaultTrackSelector(com.google.android.exoplayer2.trackselection.DefaultTrackSelector) Intent(android.content.Intent) RenderersFactory(com.google.android.exoplayer2.RenderersFactory) ExoPlayer(com.google.android.exoplayer2.ExoPlayer)

Example 2 with DebugTextViewHelper

use of com.google.android.exoplayer2.util.DebugTextViewHelper in project ExoPlayer by google.

the class TransformerActivity method playMediaItem.

@RequiresNonNull({ "playerView", "debugTextView" })
private void playMediaItem(MediaItem mediaItem) {
    playerView.setPlayer(null);
    releasePlayer();
    ExoPlayer player = new ExoPlayer.Builder(/* context= */
    this).build();
    playerView.setPlayer(player);
    player.setMediaItem(mediaItem);
    player.play();
    player.prepare();
    this.player = player;
    debugTextViewHelper = new DebugTextViewHelper(player, debugTextView);
    debugTextViewHelper.start();
}
Also used : DebugTextViewHelper(com.google.android.exoplayer2.util.DebugTextViewHelper) ExoPlayer(com.google.android.exoplayer2.ExoPlayer) RequiresNonNull(org.checkerframework.checker.nullness.qual.RequiresNonNull)

Aggregations

ExoPlayer (com.google.android.exoplayer2.ExoPlayer)2 DebugTextViewHelper (com.google.android.exoplayer2.util.DebugTextViewHelper)2 Intent (android.content.Intent)1 RenderersFactory (com.google.android.exoplayer2.RenderersFactory)1 DefaultTrackSelector (com.google.android.exoplayer2.trackselection.DefaultTrackSelector)1 EventLogger (com.google.android.exoplayer2.util.EventLogger)1 RequiresNonNull (org.checkerframework.checker.nullness.qual.RequiresNonNull)1