RepoPilot

How does the main entry point work?

About google/exoplayer · 4 messages · last activity 5/24/2026

Question

How does the main entry point work?

RepoPilot

Based on the search results and the provided data, I can describe how the main entry point works in the demo applications:

Demo Application Entry Points

The demo applications in this repository show typical ExoPlayer initialization patterns. For example, in PlayerActivity (the main demo app):

Initialization in onCreate(): In [demos/main/src/main/java/com/google/android/exoplayer2/demo/PlayerActivity.java:L111-L150], the onCreate() method:

  1. Gets the DataSourceFactory from DemoUtil.getDataSourceFactory()
  2. Sets the content view with the player UI layout
  3. Initializes the PlayerView by finding it from the layout and configuring it with error handlers and visibility listeners
  4. Restores playback state (track selection, auto-play, position) from savedInstanceState if available, or creates defaults

Lifecycle Management: In [demos/surface/src/main/java/com/google/android/exoplayer2/surfacedemo/MainActivity.java:L139-L178], the app uses Android lifecycle callbacks:

  • onResume(): Initializes the player and resumes playback
  • onPause(): Pauses playback and optionally releases resources
  • onDestroy(): Fully releases the player and related resources

The key pattern is that activities create an ExoPlayer instance on demand (typically in onResume() or onCreate() depending on API level), attach it to a PlayerView, and then release it during the appropriate lifecycle callback.

However, I don't have the core ExoPlayer library code in the provided data to show you how ExoPlayer itself is instantiated or the main initialization flow within the library itself.

FOLLOW_UPS:

  • How do you create an ExoPlayer instance?
  • What is the PlayerView component's role?
  • How does media loading work in ExoPlayer?
Question

How do you create an ExoPlayer instance?

RepoPilot

Based on the repository data, here's how you create an ExoPlayer instance:

Creating an ExoPlayer Instance

The standard pattern is to use the ExoPlayer.Builder class:

Basic Creation: In [demos/main/src/main/java/com/google/android/exoplayer2/demo/PlayerActivity.java:L280-L290], you can see:

ExoPlayer.Builder playerBuilder =
    new ExoPlayer.Builder(/* context= */ this)
        .setMediaSourceFactory(createMediaSourceFactory());
setRenderersFactory(
    playerBuilder, intent.getBooleanExtra(IntentUtil.PREFER_EXTENSION_DECODERS_EXTRA, false));
player = playerBuilder.build();

Simple Creation: In [demos/transformer/src/main/java/com/google/android/exoplayer2/transformerdemo/TransformerActivity.java:L723-L724], a minimal example:

ExoPlayer inputPlayer = new ExoPlayer.Builder(/* context= */ this).build();

And in [demos/gl/src/main/java/com/google/android/exoplayer2/gldemo/MainActivity.java:L189], another example:

ExoPlayer player = new ExoPlayer.Builder(getApplicationContext()).build();

Builder Configuration Options

The ExoPlayer.Builder allows you to configure:

  • setMediaSourceFactory(): Define how media sources are created
  • setRenderersFactory(): Specify custom renderers for handling different media types
  • Other configuration options passed via builder methods

After building, you typically:

  1. Set media items with player.setMediaItems(mediaItems)
  2. Call player.prepare() to prepare playback
  3. Attach to a PlayerView with playerView.setPlayer(player)
  4. Call player.play() to start playback

FOLLOW_UPS:

  • What builder configuration options are available?
  • How do you set media items on a player?
  • How does the RenderersFactory work?

Want to ask your own question?

Open chat for google/exoplayer

Public Q&A. Generated by RepoPilot from the actual source of google/exoplayer. AI answers can be incomplete or stale — verify before relying on them.