How does the main entry point work?
How does the main entry point work?
About google/exoplayer · 4 messages · last activity 5/24/2026
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:
- Gets the
DataSourceFactoryfromDemoUtil.getDataSourceFactory() - Sets the content view with the player UI layout
- Initializes the
PlayerViewby finding it from the layout and configuring it with error handlers and visibility listeners - Restores playback state (track selection, auto-play, position) from
savedInstanceStateif 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 playbackonPause(): Pauses playback and optionally releases resourcesonDestroy(): 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?
How do you create an ExoPlayer instance?
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 createdsetRenderersFactory(): Specify custom renderers for handling different media types- Other configuration options passed via builder methods
After building, you typically:
- Set media items with
player.setMediaItems(mediaItems) - Call
player.prepare()to prepare playback - Attach to a PlayerView with
playerView.setPlayer(player) - 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.