Simple Music Player App in Android Studio
17, Apr 2025
Build a Simple Music Player App in Android Studio (Java) – Step-by-Step for Beginners

 

Are you just starting your Android development journey? Looking for a simple and fun project to practice core concepts? In this beginner-friendly tutorial, we’ll guide you through creating a basic music player app using Java in Android Studio.

 

This hands-on project is great for learning about:

 

  1. Android UI components
  2. Working with MediaPlayer
  3. Handling audio files
  4. Structuring layouts using LinearLayout

 

Let’s get started!

 

 

Prerequisites Before You Begin

 

Before diving into this project, you should have basic knowledge of:

 

  1. Android Fundamentals
  2. Setting up Android Studio
  3. Creating and running your first Android project

 

What You’ll Learn

 

By the end of this tutorial, you’ll understand:

 

  1. How to use the MediaPlayer class and its core methods: start, pause, and stop
  2. How to use external assets (like images and audio) in your Android project
  3. How to design a simple UI using XML
  4. How to integrate audio playback controls (Play, Pause, Stop)

 

 

Step-by-Step Guide to Build a Music Player App in Android Studio

 

Step 1: Create a New Android Project

 

  1. Open Android Studio.
  2. Select “Empty Activity”.
  3. Choose Java as your language.
  4. Name your project (e.g., `SimpleMusicPlayer`). Make sure the project name starts with a capital letter.

 

 

Step 2: Design the User Interface (activity_main.xml)

 

We’ll use two layouts to build our UI:

 

  1. A Vertical LinearLayout for overall screen structure
  2. A Horizontal LinearLayout for button alignment

 

 

Components:

 

ImageView: Displays an image representing the song.

 

Three Buttons:

 

  1. Play Button (▶️)
  2. Pause Button (⏸️)
  3. Stop Button (⏹️)

 

 

Note: When you press “Play” after “Pause”, the music resumes. If you press “Play” after “Stop”, it starts from the beginning.

 

 

Step 3: Add Your MP3 File to the Raw Folder

 

1. Navigate to:

app -> src -> main -> res

2. If a `raw` folder doesn’t exist:

Right-click on res > New > Directory
Name it `raw`

 

3. Copy and paste your `.mp3` file into this folder (use all lowercase for filenames, e.g., `sound.mp3`)

 

 

Step 4: Add Java Code in MainActivity.java

 

Inside `MainActivity.java`, use the MediaPlayer class to manage audio playback.

 

Down;oad

 

> Note: The stop method releases the current audio. Re-initializing it is necessary to play again.

 

 

Step 5: Run the App

 

You can test the app using:

Emulator (AVD): Recommended RAM – 4GB or higher.
Physical Android Device:

 

  1. Enable Developer Options
  2. Turn on USB Debugging
  3. Connect your phone via USB and run the app

 

 

Final Result

 

Your app will display an image with three control buttons (Play, Pause, Stop) below. When you click Play, the music starts. Pause temporarily halts the audio, and Stop ends it completely.

 

 

Summary

 

In this beginner Android project, you learned how to:

 

  1. Design a user-friendly interface
  2. Handle media playback using Java
  3. Use local assets (images, audio)
  4. Understand layout hierarchies with LinearLayout

This simple yet practical app lays a solid foundation for building more complex multimedia Android applications.

 

Next Steps

 

Ready to take it further? Try adding:

 

  1. SeekBar for music progress
  2. Multiple audio tracks
  3. Background music service
  4. Music notifications

 

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Posts

How to Build a Basic Stopwatch App in Android Studio

    In this tutorial, we’ll create a simple Stopwatch Android App. This app will display the elapsed time and…

How to Build a Video Player in Android Studio with Dialog Transition Between Two Videos

    In this tutorial, we’ll learn how to create a basic Video Player app in Android Studio that plays…

How to Run Your First Android App in Android Studio

    Once you’ve successfully set up your Android project in Android Studio, it automatically generates a set of default…