Java Code Examples for com.google.android.exoplayer2.SimpleExoPlayer#addListener()

The following examples show how to use com.google.android.exoplayer2.SimpleExoPlayer#addListener() . 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: ExoPlayerManager.java    From PreviewSeekBar with Apache License 2.0 6 votes vote down vote up
private SimpleExoPlayer createPlayer() {
    SimpleExoPlayer player = new SimpleExoPlayer.Builder(playerView.getContext()).build();
    player.setPlayWhenReady(true);
    player.prepare(mediaSourceBuilder.getMediaSource(false));
    player.addListener(eventListener);
    return player;
}
 
Example 2
Source File: CustomExoPlayerView.java    From leafpicrevived with GNU General Public License v3.0 5 votes vote down vote up
public void setPlayer(SimpleExoPlayer player) {
    if (this.player == player) {
        return;
    }
    if (this.player != null) {

        this.player.removeListener(componentListener);
        this.player.removeTextOutput(componentListener);
        this.player.removeVideoListener(componentListener);
        if (surfaceView instanceof TextureView) {
            this.player.clearVideoTextureView((TextureView) surfaceView);
        } else if (surfaceView instanceof SurfaceView) {
            this.player.clearVideoSurfaceView((SurfaceView) surfaceView);
        }
    }
    this.player = player;
    if (useController) {
        controller.setPlayer(player);
    }
    if (shutterView != null) {
        shutterView.setVisibility(VISIBLE);
    }

    if (player != null) {

        if (surfaceView instanceof TextureView) {
            player.setVideoTextureView((TextureView) surfaceView);
        } else if (surfaceView instanceof SurfaceView) {
            player.setVideoSurfaceView((SurfaceView) surfaceView);
        }
        player.addVideoListener(componentListener);
        player.addTextOutput(componentListener);
        player.addListener(componentListener);
        maybeShowController(false);
    } else {
        shutterView.setVisibility(VISIBLE);
        controller.hide();
    }
}
 
Example 3
Source File: TubiExoPlayerView.java    From TubiPlayer with MIT License 5 votes vote down vote up
/**
 * Set the {@link SimpleExoPlayer} to use. The {@link SimpleExoPlayer#setTextOutput} and
 * {@link SimpleExoPlayer#setVideoListener} method of the player will be called and previous
 * assignments are overridden.
 *
 * @param player The {@link SimpleExoPlayer} to use.
 */
public void setPlayer(SimpleExoPlayer player, @NonNull PlaybackActionCallback playbackActionCallback) {
    if (this.player == player) {
        return;
    }
    if (this.player != null) {
        this.player.removeListener(componentListener);
        this.player.clearTextOutput(componentListener);
        this.player.clearVideoListener(componentListener);
        if (surfaceView instanceof TextureView) {
            this.player.clearVideoTextureView((TextureView) surfaceView);
        } else if (surfaceView instanceof SurfaceView) {
            this.player.clearVideoSurfaceView((SurfaceView) surfaceView);
        }
    }
    this.player = player;

    if (userController != null) {
        userController.setPlayer(player, playbackActionCallback, this);
    }

    if (shutterView != null) {
        shutterView.setVisibility(VISIBLE);
    }
    if (player != null) {
        if (surfaceView instanceof TextureView) {
            player.setVideoTextureView((TextureView) surfaceView);
        } else if (surfaceView instanceof SurfaceView) {
            player.setVideoSurfaceView((SurfaceView) surfaceView);
        }
        player.setVideoListener(componentListener);
        player.setTextOutput(componentListener);
        player.addListener(componentListener);
    }
}
 
Example 4
Source File: ExoVideoView.java    From ExoVideoView with Apache License 2.0 5 votes vote down vote up
/**
 * Set the {@link SimpleExoPlayer} to use.
 * <p>
 * To transition a {@link SimpleExoPlayer} from targeting one view to another, it's recommended to
 * use {@link #switchTargetView(SimpleExoPlayer, ExoVideoView, ExoVideoView)} rather
 * than this method. If you do wish to use this method directly, be sure to attach the player to
 * the new view <em>before</em> calling {@code setPlayer(null)} to detach it from the old one.
 * This ordering is significantly more efficient and may allow for more seamless transitions.
 *
 * @param player The {@link SimpleExoPlayer} to use.
 */
public void setPlayer(SimpleExoPlayer player) {
    if (this.player == player) {
        return;
    }
    if (this.player != null) {
        this.player.removeListener(componentListener);
        this.player.removeTextOutput(componentListener);
        this.player.removeVideoListener(componentListener);
        if (surfaceView instanceof TextureView) {
            this.player.clearVideoTextureView((TextureView) surfaceView);
        } else if (surfaceView instanceof SurfaceView) {
            this.player.clearVideoSurfaceView((SurfaceView) surfaceView);
        }
    }
    this.player = player;
    if (useController) {
        controller.setPlayer(player);
    }
    if (shutterView != null) {
        shutterView.setVisibility(VISIBLE);
    }
    if (player != null) {
        if (surfaceView instanceof TextureView) {
            player.setVideoTextureView((TextureView) surfaceView);
        } else if (surfaceView instanceof SurfaceView) {
            player.setVideoSurfaceView((SurfaceView) surfaceView);
        }
        player.addVideoListener(componentListener);
        player.addTextOutput(componentListener);
        player.addListener(componentListener);
        maybeShowController(false);
        updateForCurrentTrackSelections();
    } else {
        hideController();
        hideArtwork();
    }
}
 
Example 5
Source File: ExoVideoView.java    From ExoVideoView with Apache License 2.0 5 votes vote down vote up
private void createExoPlayer(MediaSourceCreator creator) {
    if (player != null) {
        releasePlayer();
    }

    DefaultRenderersFactory renderersFactory = new DefaultRenderersFactory(getContext());
    renderersFactory.setExtensionRendererMode(DefaultRenderersFactory.EXTENSION_RENDERER_MODE_OFF);
    SimpleExoPlayer.Builder builder = new SimpleExoPlayer.Builder(getContext(), renderersFactory);
    TrackSelection.Factory adaptiveTrackSelectionFactory =
            new AdaptiveTrackSelection.Factory();
    DefaultTrackSelector trackSelector = new DefaultTrackSelector(getContext(),new AdaptiveTrackSelection.Factory());
    builder.setTrackSelector(new DefaultTrackSelector(getContext(),adaptiveTrackSelectionFactory));
    builder.setTrackSelector(trackSelector);
    builder.setBandwidthMeter(new DefaultBandwidthMeter.Builder(getContext()).build());
    SimpleExoPlayer internalPlayer = builder.build();
    internalPlayer.addListener(componentListener);
    internalPlayer.addListener(creator.getEventLogger());
    internalPlayer.addMetadataOutput(creator.getEventLogger());
    setPlayer(internalPlayer);
}
 
Example 6
Source File: SimpleExoPlayerView.java    From K-Sonic with MIT License 5 votes vote down vote up
/**
 * Set the {@link SimpleExoPlayer} to use. The {@link SimpleExoPlayer#setTextOutput} and
 * {@link SimpleExoPlayer#setVideoListener} method of the player will be called and previous
 * assignments are overridden.
 *
 * @param player The {@link SimpleExoPlayer} to use.
 */
public void setPlayer(SimpleExoPlayer player) {
  if (this.player == player) {
    return;
  }
  if (this.player != null) {
    this.player.setTextOutput(null);
    this.player.setVideoListener(null);
    this.player.removeListener(componentListener);
    this.player.setVideoSurface(null);
  }
  this.player = player;
  if (useController) {
    controller.setPlayer(player);
  }
  if (shutterView != null) {
    shutterView.setVisibility(VISIBLE);
  }
  if (player != null) {
    if (surfaceView instanceof TextureView) {
      player.setVideoTextureView((TextureView) surfaceView);
    } else if (surfaceView instanceof SurfaceView) {
      player.setVideoSurfaceView((SurfaceView) surfaceView);
    }
    player.setVideoListener(componentListener);
    player.addListener(componentListener);
    player.setTextOutput(componentListener);
    maybeShowController(false);
    updateForCurrentTrackSelections();
  } else {
    hideController();
    hideArtwork();
  }
}
 
Example 7
Source File: ExoPlayerView.java    From react-native-video with MIT License 5 votes vote down vote up
/**
 * Set the {@link SimpleExoPlayer} to use. The {@link SimpleExoPlayer#setTextOutput} and
 * {@link SimpleExoPlayer#setVideoListener} method of the player will be called and previous
 * assignments are overridden.
 *
 * @param player The {@link SimpleExoPlayer} to use.
 */
public void setPlayer(SimpleExoPlayer player) {
    if (this.player == player) {
        return;
    }
    if (this.player != null) {
        this.player.setTextOutput(null);
        this.player.setVideoListener(null);
        this.player.removeListener(componentListener);
        this.player.setVideoSurface(null);
    }
    this.player = player;
    shutterView.setVisibility(VISIBLE);
    if (player != null) {
        setVideoView();
        player.setVideoListener(componentListener);
        player.addListener(componentListener);
        player.setTextOutput(componentListener);
    }
}