0% found this document useful (0 votes)
122 views14 pages

Music Player Project Report

The document is a project report on the development of a music player application using Android Studio, submitted for a Master's degree in Computer Applications. It outlines the project's objectives, key features, and the development environment, including code snippets for the user interface and main activity. The report also includes details on audio playback functionalities, user interface design, and playlist management capabilities.

Uploaded by

rthe2036
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
122 views14 pages

Music Player Project Report

The document is a project report on the development of a music player application using Android Studio, submitted for a Master's degree in Computer Applications. It outlines the project's objectives, key features, and the development environment, including code snippets for the user interface and main activity. The report also includes details on audio playback functionalities, user interface design, and playlist management capabilities.

Uploaded by

rthe2036
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

A Project Report

On

Music Player

Submitted in partial fulfilment of the

requirement for the award of the degree of

MASTER OF COMPUTER APPLICATION

DEGREE
Session 2024-25
in

MCA
By
Sambhu Kumar (23SCSE2030466)
Prashant Kumar Singh (23SCSE2030400)
Anurag Kumar (23SCSE2030467)

Under the guidance of


Miss Richa Kumari

SCHOOL OF COMPUTER APPLICATION AND TECHNOLOGY

GALGOTIAS UNIVERSITY, GREATER NOIDA

INDIA

Jan, 2024
Index

S.No. Contents Page No.


1 Introduc on 2
2 Code 3-11
3 Output 12-13

1|Page
Introduc on

Crea ng a music player app in Android Studio is an engaging project that introduces
developers to key concepts in mobile applica on development. This project involves u lizing
the Android pla orm's capabili es to play audio files, manage playlists, and create a user-
friendly interface.

Overview of the Music Player Project


The primary goal of this project is to develop a simple yet func onal music player that can
play various audio formats stored on the user's device. The app will leverage the MediaPlayer
class, which provides essen al methods for audio playback, including play, pause, and stop
func onali es. Addi onally, it will incorporate a straigh orward user interface designed using
XML layouts, featuring components like bu ons for controlling playback and an ImageView
for displaying album art or song informa on.

Key Features
 Audio Playback: The app will support basic audio playback func ons, allowing users
to play, pause, and stop music tracks.
 User Interface: A clean and intui ve UI will be created using Android's layout tools,
ensuring ease of naviga on and interac on.
 Playlist Management: Users will have the ability to browse their music library and
select songs to add to a playlist.
 Background Playback: The app will con nue playing music even when the user
navigates away from it, enhancing user experience.

Development Environment

To start this project, developers need to set up their environment with Android Studio,
which is the official integrated development environment (IDE) for Android development.
Basic knowledge of Java or Kotlin programming languages is also essen al as these
languages are commonly used for Android applica ons.

By following structured tutorials and guides available online, developers can successfully
build a music player app that not only meets func onal requirements but also enhances
their understanding of mobile app development principles.

2|Page
CODE

ac vity_main.xml
<?xml version="1.0" encoding="u -8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="h p://schemas.android.com/apk/res/android"
xmlns:app="h p://schemas.android.com/apk/res-auto"
xmlns:tools="h p://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="20dp"
tools:context=".MainAc vity">

<ImageView
android:id="@+id/imgAlbumCover"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_marginTop="32dp"
android:scaleType="centerCrop"
android:src="@drawable/music_placeholder"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.471"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="ContentDescrip on,ImageContrastCheck" />

<TextView
android:id="@+id/txtSongName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:gravity="center"
android:text="No song selected"
android:textSize="18sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBo omOf="@id/imgAlbumCover"
tools:ignore="HardcodedText" />

<SeekBar

3|Page
android:id="@+id/seekBar"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBo omOf="@id/txtSongName" />

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:gravity="center"
android:orienta on="horizontal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBo omOf="@id/seekBar">

<ImageBu on
android:id="@+id/btnPlay"
android:layout_width="60dp"
android:layout_height="60dp"
android:background="?android:a r/selectableItemBackground"
android:contentDescrip on="Play"
android:src="@drawable/ic_play"
tools:ignore="HardcodedText,ImageContrastCheck" />

<ImageBu on
android:id="@+id/btnPause"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_marginStart="15dp"
android:background="?android:a r/selectableItemBackground"
android:contentDescrip on="Pause"
android:src="@drawable/ic_pause"
tools:ignore="HardcodedText,ImageContrastCheck" />

<ImageBu on
android:id="@+id/btnStop"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_marginStart="15dp"
android:background="?android:a r/selectableItemBackground"
android:contentDescrip on="Stop"

4|Page
android:src="@drawable/ic_stop"
tools:ignore="HardcodedText,ImageContrastCheck" />
</LinearLayout>

<Bu on
android:id="@+id/btnSelect"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:backgroundTint="@color/purple_500"
android:text="Select Song"
android:textColor="@android:color/white"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.532"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBo omOf="@id/btnStop"
tools:ignore="HardcodedText,NotSibling" />

<TextView
android:id="@+id/textView2"
android:layout_width="295dp"
android:layout_height="62dp"
android:layout_marginStart="52dp"
android:layout_marginEnd="47dp"
android:layout_marginBo om="56dp"
android:gravity="center"
android:text="Created by Sambhu Kumar (23SCSE2030466), Prashant Kumar Singh
(23SCSE2030400), Anurag Kumar (23SCSE2030467)"
android:textSize="14sp"
android:textStyle="bold"
app:layout_constraintBo om_toBo omOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.6"
app:layout_constraintStart_toStartOf="parent" />

<TextView
android:id="@+id/textView3"
android:layout_width="172dp"
android:layout_height="47dp"
android:layout_marginStart="122dp"
android:layout_marginEnd="105dp"
android:layout_marginBo om="184dp"
android:text="MUSIC PLAYER"
android:textSize="24sp"

5|Page
android:textStyle="bold"
app:layout_constraintBo om_toBo omOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.84"
app:layout_constraintStart_toStartOf="parent"
tools:ignore="MissingConstraints" />
</androidx.constraintlayout.widget.ConstraintLayout>

colors.xml
<?xml version="1.0" encoding="u -8"?>
<resources>
<color name="black">#FF000000</color>
<color name="white">#FFFFFFFF</color>
<color name="purple_500">#FF6200EE</color>
</resources>

music_placeholder.xml
<vector xmlns:android="h p://schemas.android.com/apk/res/android"
android:width="100dp"
android:height="100dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#BDBDBD"
android:pathData="M12 3v10.55a4 4 0 1 0 2 3.45V7h4V3h-6z"/>
</vector>

ic_play.xml
<vector xmlns:android="h p://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#FFFFFF"

6|Page
android:pathData="M8,5v14l11,-7z"/>
</vector>

ic_pause.xml
<vector xmlns:android="h p://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#FFFFFF"
android:pathData="M6,19h4V5H6zM14,5v14h4V5z"/>
</vector>

ic_stop.xml
<vector xmlns:android="h p://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#FFFFFF"
android:pathData="M6,6h12v12H6z"/>
</vector>

AndroidManifest.xml
<?xml version="1.0" encoding="u -8"?>
<manifest xmlns:android="h p://schemas.android.com/apk/res/android"
xmlns:tools="h p://schemas.android.com/tools">
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"
android:maxSdkVersion="32"/>

<applica on
android:allowBackup="true"

7|Page
android:dataExtrac onRules="@xml/data_extrac on_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.MusicPlayer"
tools:targetApi="31">
<ac vity
android:name=".MainAc vity"
android:exported="true">
<intent-filter>
<ac on android:name="android.intent.ac on.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</ac vity>
</applica on>
</manifest>

MainAc vity.java
package com.example.musicplayer;

import android.content.Intent;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.widget.Bu on;
import android.widget.ImageBu on;
import android.widget.ImageView;
import android.widget.SeekBar;
import android.widget.TextView;
import androidx.ac vity.result.Ac vityResultLauncher;
import androidx.ac vity.result.contract.Ac vityResultContracts;
import androidx.annota on.Nullable;
import androidx.appcompat.app.AppCompatAc vity;

import java.io.IOExcep on;


public class MainAc vity extends AppCompatAc vity {
private ImageBu on btnPlay, btnPause, btnStop;
private Bu on btnSelect;

8|Page
private SeekBar seekBar;
private TextView txtSongName;
private ImageView imgAlbumCover;
private MediaPlayer mediaPlayer;
private Handler handler = new Handler();
private Uri selectedSongUri;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.ac vity_main);

// Link UI elements with IDs


btnPlay = findViewById(R.id.btnPlay);
btnPause = findViewById(R.id.btnPause);
btnStop = findViewById(R.id.btnStop);
btnSelect = findViewById(R.id.btnSelect);
seekBar = findViewById(R.id.seekBar);
txtSongName = findViewById(R.id.txtSongName);
imgAlbumCover = findViewById(R.id.imgAlbumCover);

// Ini alize MediaPlayer


mediaPlayer = new MediaPlayer();

// Select song from storage


btnSelect.setOnClickListener(v -> pickAudioFile());

// Play bu on
btnPlay.setOnClickListener(v -> {
if (selectedSongUri != null) {
playAudio();
}
});

// Pause bu on
btnPause.setOnClickListener(v -> {
if (mediaPlayer.isPlaying()) {
mediaPlayer.pause();
}
});

// Stop bu on
btnStop.setOnClickListener(v -> {
if (mediaPlayer.isPlaying() || mediaPlayer.getCurrentPosi on() > 0) {

9|Page
mediaPlayer.stop();
mediaPlayer.reset();
seekBar.setProgress(0);
}
});

// SeekBar listener
seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
if (fromUser) {
mediaPlayer.seekTo(progress);
}
}

@Override
public void onStartTrackingTouch(SeekBar seekBar) {}

@Override
public void onStopTrackingTouch(SeekBar seekBar) {}
});
}

// Open file picker to select an audio file


private void pickAudioFile() {
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("audio/*");
selectAudioLauncher.launch(intent);
}

// Handle selected audio file


private final Ac vityResultLauncher<Intent> selectAudioLauncher =
registerForAc vityResult(
new Ac vityResultContracts.StartAc vityForResult(),
result -> {
if (result.getResultCode() == RESULT_OK && result.getData() != null) {
selectedSongUri = result.getData().getData();
String fileName = getFileNameFromUri(selectedSongUri);
txtSongName.setText(fileName);
playAudio();
}
}
);

10 | P a g e
// Play selected audio file
private void playAudio() {
try {
mediaPlayer.reset();
mediaPlayer.setDataSource(this, selectedSongUri);
mediaPlayer.prepare();
mediaPlayer.start();
seekBar.setMax(mediaPlayer.getDura on());

// Update SeekBar
updateSeekBar();
} catch (IOExcep on e) {
e.printStackTrace();
}
}

// Update SeekBar in real- me


private void updateSeekBar() {
handler.postDelayed(() -> {
if (mediaPlayer.isPlaying()) {
seekBar.setProgress(mediaPlayer.getCurrentPosi on());
updateSeekBar();
}
}, 1000);
}

// Get file name from URI


private String getFileNameFromUri(Uri uri) {
String path = uri.getPath();
return path != null ? path.substring(path.lastIndexOf("/") + 1) : "Unknown";
}

@Override
protected void onDestroy() {
super.onDestroy();
if (mediaPlayer != null) {
mediaPlayer.release();
mediaPlayer = null;
}
}
}

11 | P a g e
OUTPUT

12 | P a g e
13 | P a g e

You might also like