In this tutorial, we’ll learn how to create a basic Video Player app in Android Studio that plays two videos stored in the app’s resources. Once the first video finishes playing, a dialog box will appear asking the user whether to replay the current video or play the next.
Step 1: Add Videos to the Project
Navigate to:
app > res > raw
(If the raw folder doesn’t exist, right-click res > New > Android Resource Directory > Name it “raw”.)
Paste the video files (e.g., faded.mp4, aeroplane.mp4) into the raw folder.
Step 2: Design the Layout (activity_main.xml)
Step 3: Java Backend (MainActivity.java)
- Declare Variables and Initialize Components
- Set Up onCreate()
Step 4: Define setVideo() Method
This method sets up and starts the video from the raw folder.
Step 5: Create Dialog After Video Completion
- This dialog gives the user two choices—replay or play the next video.
- App Behavior Summary
- On app launch, the first video starts playing automatically.
Once it ends, a dialog box appears prompting:
- Replay the current video
- Play the next video
On clicking “Next”, the second video begins.
If there are no more videos, a toast message is displayed.
Tips
- Ensure videos are in .mp4 format and not too large in size.
- You can expand the video list to include more files.
- This is a simple structure—feel free to enhance it with thumbnails, progress bars, or full-screen modes.