Video streaming is no longer limited to OTT platforms like Netflix or YouTube. Today, e-learning apps, news apps, fitness apps, and even government apps use video streaming heavily.
In this tutorial, you’ll learn how to build a real-world Android video streaming system using:
- ExoPlayer – Google’s official advanced video player
- Firebase Storage – to host video files
- Firebase Firestore – to manage video metadata dynamically
This setup is scalable, secure, and production-ready.
Why Not Use Android VideoView?
Many beginners start with VideoView, but it has serious limitations:
- No adaptive bitrate streaming
- Poor buffering control
- Limited format support
- No analytics or customization
ExoPlayer solves all of these problems and is officially recommended by Google.
Project Architecture (How Everything Works)
Here’s how data flows in our app:
- Videos are uploaded to Firebase Storage
- Video metadata (title, URL, thumbnail) is stored in Firestore
- The app fetches metadata from Firestore
- ExoPlayer streams video directly from Firebase Storage
This approach allows you to update videos without updating the app.
Step 1: Add ExoPlayer Dependency
ExoPlayer is now part of AndroidX Media3. Add the following dependencies:
implementation "androidx.media3:media3-exoplayer:1.2.1"
implementation "androidx.media3:media3-ui:1.2.1"
Media3 provides better lifecycle handling and future updates.
Step 2: Setup Firebase in Your Project
Create a project in Firebase Console and connect your Android app.
Then add Firebase dependencies:
implementation 'com.google.firebase:firebase-firestore-ktx'
implementation 'com.google.firebase:firebase-storage-ktx'
Firestore is used for dynamic content, while Storage handles large video files efficiently.
Step 3: Upload Videos to Firebase Storage
Upload MP4 videos (H.264 codec recommended) to Firebase Storage.
Suggested folder structure:
/videos
intro.mp4
lesson1.mp4
lesson2.mp4
Avoid very large files; split long content into smaller segments.
Step 4: Store Metadata in Firestore
Instead of hardcoding URLs, store video details in Firestore.
{
"title": "Firebase ExoPlayer Tutorial",
"videoUrl": "https://firebasestorage.googleapis.com/...",
"thumbnail": "https://image-url",
"duration": "12:30"
}
This allows instant updates without app releases.
Step 5: Design ExoPlayer UI
Use PlayerView instead of custom video layouts.
<androidx.media3.ui.PlayerView
android:id="@+id/playerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:use_controller="true" />
This automatically provides play, pause, seek, and fullscreen controls.
Step 6: Initialize ExoPlayer
Initialize ExoPlayer only when the video URL is available.
private lateinit var player: ExoPlayer
private fun initializePlayer(videoUrl: String) {
player = ExoPlayer.Builder(this).build()
binding.playerView.player = player
val mediaItem = MediaItem.fromUri(videoUrl)
player.setMediaItem(mediaItem)
player.prepare()
player.playWhenReady = true
}
Step 7: Fetch Video from Firestore
Now fetch the video URL dynamically.
FirebaseFirestore.getInstance()
.collection("videos")
.document("video_id")
.get()
.addOnSuccessListener {
it.getString("videoUrl")?.let { url ->
initializePlayer(url)
}
}
Step 8: Handle Lifecycle Correctly
Failing to release ExoPlayer causes memory leaks.
override fun onStop() {
super.onStop()
player.release()
}
Best Practices for Production Apps
- Use adaptive bitrate streaming
- Enable Firebase Storage security rules
- Add caching for smoother playback
- Track user engagement analytics
Real-World Use Cases
- Online course platforms
- Government training apps
- Fitness & yoga apps
- Private OTT platforms
Conclusion
Firebase + ExoPlayer is a battle-tested combination for Android video streaming. With this setup, you can scale content, update videos remotely, and deliver a smooth viewing experience.

Post a Comment