0% found this document useful (0 votes)
10 views30 pages

Index: Sr. No. Page No

The document outlines a micro-project proposal and report for developing a music player application using Java and XML on the Android platform. It details the aims, methodology, action plan, required resources, and the actual methodology followed during the project. Additionally, it includes a literature review on the emotional impact of music and provides source code for the application.

Uploaded by

Ganesh Ghumare
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)
10 views30 pages

Index: Sr. No. Page No

The document outlines a micro-project proposal and report for developing a music player application using Java and XML on the Android platform. It details the aims, methodology, action plan, required resources, and the actual methodology followed during the project. Additionally, it includes a literature review on the emotional impact of music and provides source code for the application.

Uploaded by

Ganesh Ghumare
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/ 30

Index

Sr. No. Contents Page No.

Annexure I– Micro Project Proposal 2-3

1.Aims/Benefits of the Micro-Project 2

2. Course Outcome Addressed 2

1 3.Proposed Methodology 2

4. Action Plan 2-3

5. Resources Required 4

6. Name of student with roll no 4

Annexure II – Micro Project Report 5-30

1.Rationale 4

2.Aims/Benefits of the Micro-Project 4

3.Course Outcome Achieve 4

4. Literature Review 4-6

2 5.Actual Methodology Followed 6-7

6. Actual Resources Used 7

7. Source Code 7-29

8. Output 30

9. Skill developed out of this Micro-Project: 30

10. Applications of this Micro-Project 30

1
Annexure I
Micro Project Proposal
Develop a Music Player using Java and XML in Android

1. Aims/Benefits of the Micro-Project:


The music player app that we will develop would allow the users to play the songs present on the
device. You can download songs on your device and then use the music player to play those songs.

2. Course Outcome Addressed:


a. Interpret feature of Android operating system
b. Configure Android environment and development tools
c. Develop rich user interface by using layouts and controls
d. Use User Interface components for android application development
e. Publish Android Applications

3. Proposed Methodology:
Music player in this project is application software based on Google Android. Music is one of the
best ways to relieve pressure in stressful modern society life. The purpose of this project is to
develop a player which can play the mainstream file format. To browse and query the storage space
as well as operation of playing can be realized. Meanwhile, this software can play, pause and select
songs with latest button and next button according to sets requirement as well as set up songs.

2
4. Action Plan:

Sr. Details of Activity Planned Planned Name of Responsible


No. Start date Finish date Team Members
Search the topic 25/02/2022 02/03/2022
1
10:30am – 12:30pm 10:30am – 12:30pm
Search the information 02/03/2022 05/03/2022
2
10:30am – 12:30pm 10:30am – 12:30pm
Analysis the information 05/03/2022 12/03/2022
3
10:30am – 12:30pm 10:30am – 12:30pm

Draw the flowchart 12/03/2022 19/03/2022


4
10:30am – 12:30pm 10:30am – 12:30pm

Developing a program 19/03/2022 26/03/2022


5
10:30am – 12:30pm 10:30am – 12:30pm Gandharv Nitin
Write an algorithm 26/03/2022 02/04/2022 Kulkarni
6
10:30am – 12:30pm 10:30am – 12:30pm

Initialize of checklist 02/04/2022 06/04/2022


7
10:30am – 12:30pm 10:30am – 12:30pm

Choose instructions 06/04/2022 10/04/2022


8
10:30am – 12:30pm 10:30am – 12:30pm

Convert algorithm to ALP 10/04/2022 13/04/2022


9
10:30am – 12:30pm 10:30am – 12:30pm

Final submission date 13/04/2022 13/04/2022


10
10:30am – 12:30pm 10:30am – 12:30pm

3
5. Resources Required:

Sr.No. Name of resource / material Specification Quantity Remarks


WINDOWS 10, 8GB
1 Computer 1
RAM, 256 GB SSD
2 Operating System WINDOWS 10 1

3 Browser Chrome 1

4 IDE Android Studio 1

6. Names of Team Member with Roll No.:

Sr. No. Enrollment No. Name of Team Member Roll No.

1 1910950187 Gandharv Nitin Kulkarni 62

Mrs. Joshi R. D.
Name and Signature of the Teacher

4
Annexure – II
Micro-Project Report
Develop a Music Player using Java and XML in Android

1. Rationale:
Android application development is one of the rising and growing trends in the industry of mobile.
This course examines the principles of mobile application design and covers the necessary
concepts which are required to understand mobile based applications and develop Android based
Applications in particular.

2. Aims/Benefits of the Micro-Project:


The music player app that we will develop would allow the users to play the songs present on the
device. You can download songs on your device and then use the music player to play those songs.

3. Course Outcomes Achieved:


a. Interpret feature of Android operating system
b. Configure Android environment and development tools
c. Develop rich user interface by using layouts and controls
d. Use User Interface components for android application development
e. Publish Android Applications

4. Literature Review:
Music and its use for emotion regulation processes, still remains an unanswered question. Many
experimental layouts encompassing its daily life use and clinical applications across different
cultures and continents have preserved music as a self-regulative tool. Music intervention and
emotion regulation measures were viewed and included only when at least forms of music
participation (singing, playing, listening, and engagement) were noted in the study and effects on
emotion regulation were directly measured. The interrelations between the effects of music on
emotion regulation and the use of it as a purposeful instrument, e.g., educational or therapeutic
functions, yielded limited results, music interventions for specific. Music has a’ regulative capacity
of itself’, but is confined as valuable instrument for specific emotion regulation interventions.

5
Emotions can appear in most parts of human-to-human communication and often provide
additional information about a message. As some emotion expressions are culturally independent-
even in a foreign language where we do not understand the meaning of words it is relatively easy
for anyone to recognize surprise, scare, anger, etc. in the message. Also, in the depiction of our
face expressions it is not so important if we grew up in USA, Britain or China, most of such
expressions are very similar and have a similar meaning. The problem arises with text documents.
Any sentence or document is strongly dependent on the language it was written in. Also, similar
languages have often different spelling and often also a bit different.
So, music songs in the recent years have become a popular choice to depict human
emotions. Initially, it was a tedious task to label songs based on the emotions they depict from a
collection on large database of songs. But audio and lyrics of songs become ways of extracting the
emotions and helped to distinguish the different human emotions. Also, it is known that individuals
perceive emotions within music differently. Knowing the many existing approaches for modelling
the ambiguities of musical mood, a complete system would need to incorporate some level of
individual profiling to adjust its predictions. The music in a way helps to derive the emotional
mood of an individual as songs depict emotions i.e., they are meaningful words arranged in a
sequence to convey thoughts or messages to others.
The clinical as well as the non-clinical studies, all demonstrate the effective use of music
as self-regulative tool for emotions. Regardless of the difference between the study designs, using
active music making and listening versus reflective and non-experimental use of music, all studies
revealed the individual applications of music for personal employ, promoting self-regulative skills
for positive reconciliation, which are culturally differentiate between all tested societies. These
implementations brace the general agreement of this review that music listening is most frequently
used with a large range of goals and strategies for emotional regulation purposes.

5. Actual Methodology Followed:


The application of android needs to run based on Android environment.
The following is the configuration requirement and installation steps of Android development
environment:
The required software of the developing environment
a. Operation system: Windows 10, Linux

6
b. Software: Android SDK (Software Development Kit) ADT (Android Development Tool)
c. JDK: Java Runtime Environment virtual machine,Java Development Kit (JDK)
Installation steps of the developing environment
Step 1: install the Java virtual machine JDK version - 7
Step 2: install the Android SDK: first download the Android SDK
Download address: http://developer-android-com/sdk/index-html
Input SDK tools path in the SDK location: D: \ android \ software \ android
SDK– Windows and click OK.
The Android environment is set up successfully.

6. Actual Resources Used:

Sr. Name of resource /


Specification Quantity Remarks
No. material

WINDOWS 10, 8GB


1 Computer 1
RAM, 256 GB SSD
2 Operating System WINDOWS 10 1

3 Browser Chrome 1

4 IDE Android Studio 1

7. Source Code:
XML File:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"

7
tools:context=".Activity.MainActivity">

<RelativeLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent">

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:theme="@style/ThemeOverlay.AppCompat.ActionBar" />

<LinearLayout
android:id="@+id/ll_include_controls"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/toolbar">

<include layout="@layout/player_layout" />

</LinearLayout>

<LinearLayout
android:id="@+id/ll_tab_layout"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_below="@id/ll_include_controls"
android:background="@color/colorPrimary">

8
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="10dp"
app:tabBackground="@color/colorPrimary"
app:tabGravity="fill"
app:tabIndicatorColor="@color/colorPrimary"
app:tabMode="fixed"
app:tabSelectedTextColor="@color/text_color"
app:tabTextColor="@color/off_color" />
</LinearLayout>

<android.support.v4.view.ViewPager
android:id="@+id/songs_viewpager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/ll_tab_layout"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />

<android.support.design.widget.FloatingActionButton
android:id="@+id/btn_refresh"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_marginBottom="15dp"
android:layout_marginEnd="15dp"
android:focusable="true"
android:src="@drawable/refresh_icon"

9
app:backgroundTint="@color/colorPrimary"
app:layout_anchor="@id/songs_viewpager" />

</RelativeLayout>

<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="@color/drawer_color"
android:fitsSystemWindows="true"
app:headerLayout="@layout/drawer_header_layout"
app:itemIconTint="@color/text_color"
app:itemTextColor="@color/text_color"
app:menu="@menu/navigation_menu" />

</android.support.v4.widget.DrawerLayout>
Java File:
package com.example.soc_macmini_15.musicplayer.Activity;

import android.Manifest;
import android.app.SearchManager;
import android.content.Context;
import android.content.DialogInterface;
import android.content.pm.PackageManager;
import android.media.MediaPlayer;
import android.os.Handler;
import android.support.annotation.NonNull;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.NavigationView;

10
import android.support.design.widget.Snackbar;
import android.support.design.widget.TabLayout;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v4.view.ViewPager;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

import android.view.Gravity;
import android.view.Menu;
import android.view.MenuItem;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.ImageButton;
import android.widget.SearchView;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.Toast;

import com.example.soc_macmini_15.musicplayer.Adapter.ViewPagerAdapter;
import com.example.soc_macmini_15.musicplayer.DB.FavoritesOperations;
import com.example.soc_macmini_15.musicplayer.Fragments.AllSongFragment;
import com.example.soc_macmini_15.musicplayer.Fragments.CurrentSongFragment;
import com.example.soc_macmini_15.musicplayer.Fragments.FavSongFragment;
import com.example.soc_macmini_15.musicplayer.Model.SongsList;
import com.example.soc_macmini_15.musicplayer.R;

import java.util.ArrayList;

11
public class MainActivity extends AppCompatActivity implements View.OnClickListener,
AllSongFragment.createDataParse, FavSongFragment.createDataParsed,
CurrentSongFragment.createDataParsed {

private Menu menu;

private ImageButton imgBtnPlayPause, imgbtnReplay, imgBtnPrev, imgBtnNext,


imgBtnSetting;
private TabLayout tabLayout;
private ViewPager viewPager;
private SeekBar seekbarController;
private DrawerLayout mDrawerLayout;
private TextView tvCurrentTime, tvTotalTime;

private ArrayList<SongsList> songList;


private int currentPosition;
private String searchText = "";
private SongsList currSong;

private boolean checkFlag = false, repeatFlag = false, playContinueFlag = false, favFlag =


true, playlistFlag = false;
private final int MY_PERMISSION_REQUEST = 100;
private int allSongLength;

MediaPlayer mediaPlayer;
Handler handler;
Runnable runnable;

12
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
init();
grantedPermission();

/**
* Initialising the views
*/

private void init() {


imgBtnPrev = findViewById(R.id.img_btn_previous);
imgBtnNext = findViewById(R.id.img_btn_next);
imgbtnReplay = findViewById(R.id.img_btn_replay);
imgBtnSetting = findViewById(R.id.img_btn_setting);

tvCurrentTime = findViewById(R.id.tv_current_time);
tvTotalTime = findViewById(R.id.tv_total_time);
FloatingActionButton refreshSongs = findViewById(R.id.btn_refresh);
seekbarController = findViewById(R.id.seekbar_controller);
viewPager = findViewById(R.id.songs_viewpager);
NavigationView navigationView = findViewById(R.id.nav_view);
mDrawerLayout = findViewById(R.id.drawer_layout);
imgBtnPlayPause = findViewById(R.id.img_btn_play);
Toolbar toolbar = findViewById(R.id.toolbar);
handler = new Handler();
mediaPlayer = new MediaPlayer();

13
toolbar.setTitleTextColor(getResources().getColor(R.color.text_color));
setSupportActionBar(toolbar);

ActionBar actionBar = getSupportActionBar();


assert actionBar != null;
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setHomeAsUpIndicator(R.drawable.menu_icon);

imgBtnNext.setOnClickListener(this);
imgBtnPrev.setOnClickListener(this);
imgbtnReplay.setOnClickListener(this);
refreshSongs.setOnClickListener(this);
imgBtnPlayPause.setOnClickListener(this);
imgBtnSetting.setOnClickListener(this);

navigationView.setNavigationItemSelectedListener(new
NavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
item.setChecked(true);
mDrawerLayout.closeDrawers();
switch (item.getItemId()) {
case R.id.nav_about:
about();
break;
}
return true;
}
});
}

14
/**
* Function to ask user to grant the permission.
*/

private void grantedPermission() {


if (ContextCompat.checkSelfPermission(MainActivity.this,
Manifest.permission.READ_EXTERNAL_STORAGE) !=
PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(MainActivity.this,
new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
MY_PERMISSION_REQUEST);
if (ActivityCompat.shouldShowRequestPermissionRationale(MainActivity.this,
Manifest.permission.READ_EXTERNAL_STORAGE)) {
ActivityCompat.requestPermissions(MainActivity.this,
new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
MY_PERMISSION_REQUEST);
} else {
if (ContextCompat.checkSelfPermission(MainActivity.this,
Manifest.permission.READ_EXTERNAL_STORAGE) !=
PackageManager.PERMISSION_GRANTED) {
Snackbar snackbar = Snackbar.make(mDrawerLayout, "Provide the Storage
Permission", Snackbar.LENGTH_LONG);
snackbar.show();
}
}
} else {
setPagerLayout();
}
}

/**

15
* Checking if the permission is granted or not
*
* @param requestCode
* @param permissions
* @param grantResults
*/
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
@NonNull int[] grantResults) {
switch (requestCode) {
case MY_PERMISSION_REQUEST:
if (grantResults.length > 0 && grantResults[0] ==
PackageManager.PERMISSION_GRANTED) {
if (ContextCompat.checkSelfPermission(MainActivity.this,
Manifest.permission.READ_EXTERNAL_STORAGE) ==
PackageManager.PERMISSION_GRANTED) {
Toast.makeText(this, "Permission Granted!", Toast.LENGTH_SHORT).show();
setPagerLayout();
} else {
Snackbar snackbar = Snackbar.make(mDrawerLayout, "Provide the Storage
Permission", Snackbar.LENGTH_LONG);
snackbar.show();
finish();
}
}
}
}

/**
* Setting up the tab layout with the viewpager in it.
*/

16
private void setPagerLayout() {
ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager(),
getContentResolver());
viewPager.setAdapter(adapter);
viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

@Override
public void onPageSelected(int position) {

@Override
public void onPageScrollStateChanged(int state) {

}
});

tabLayout = findViewById(R.id.tabs);
tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);
tabLayout.setupWithViewPager(viewPager);
tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
@Override
public void onTabSelected(TabLayout.Tab tab) {
viewPager.setCurrentItem(tab.getPosition());
}

17
@Override
public void onTabUnselected(TabLayout.Tab tab) {

@Override
public void onTabReselected(TabLayout.Tab tab) {

}
});

/**
* Function to show the dialog for about us.
*/
private void about() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(getString(R.string.about))
.setMessage(getString(R.string.about_text))
.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {

}
});
AlertDialog alertDialog = builder.create();
alertDialog.show();
}

@Override

18
public boolean onCreateOptionsMenu(Menu menu) {
this.menu = menu;
getMenuInflater().inflate(R.menu.action_bar_menu, menu);
SearchManager manager = (SearchManager)
getSystemService(Context.SEARCH_SERVICE);
SearchView searchView = (SearchView)
menu.findItem(R.id.menu_search).getActionView();
searchView.setSearchableInfo(manager.getSearchableInfo(getComponentName()));
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
return false;
}

@Override
public boolean onQueryTextChange(String newText) {
searchText = newText;
queryText();
setPagerLayout();
return true;
}
});

return super.onCreateOptionsMenu(menu);
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {

switch (item.getItemId()) {
case android.R.id.home:

19
mDrawerLayout.openDrawer(Gravity.START);
return true;
case R.id.menu_search:
Toast.makeText(this, "Search", Toast.LENGTH_SHORT).show();
return true;
case R.id.menu_favorites:
if (checkFlag)
if (mediaPlayer != null) {
if (favFlag) {
Toast.makeText(this, "Added to Favorites", Toast.LENGTH_SHORT).show();
item.setIcon(R.drawable.ic_favorite_filled);
SongsList favList = new SongsList(songList.get(currentPosition).getTitle(),
songList.get(currentPosition).getSubTitle(),
songList.get(currentPosition).getPath());
FavoritesOperations favoritesOperations = new FavoritesOperations(this);
favoritesOperations.addSongFav(favList);
setPagerLayout();
favFlag = false;
} else {
item.setIcon(R.drawable.favorite_icon);
favFlag = true;
}
}
return true;
}

return super.onOptionsItemSelected(item);

20
/**
* Function to handle the click events.
*
* @param v
*/
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.img_btn_play:
if (checkFlag) {
if (mediaPlayer.isPlaying()) {
mediaPlayer.pause();
imgBtnPlayPause.setImageResource(R.drawable.play_icon);
} else if (!mediaPlayer.isPlaying()) {
mediaPlayer.start();
imgBtnPlayPause.setImageResource(R.drawable.pause_icon);
playCycle();
}
} else {
Toast.makeText(this, "Select the Song ..", Toast.LENGTH_SHORT).show();
}
break;
case R.id.btn_refresh:
Toast.makeText(this, "Refreshing", Toast.LENGTH_SHORT).show();
setPagerLayout();
break;
case R.id.img_btn_replay:

if (repeatFlag) {
Toast.makeText(this, "Replaying Removed..", Toast.LENGTH_SHORT).show();
mediaPlayer.setLooping(false);

21
repeatFlag = false;
} else {
Toast.makeText(this, "Replaying Added..", Toast.LENGTH_SHORT).show();
mediaPlayer.setLooping(true);
repeatFlag = true;
}
break;
case R.id.img_btn_previous:
if (checkFlag) {
if (mediaPlayer.getCurrentPosition() > 10) {
if (currentPosition - 1 > -1) {
attachMusic(songList.get(currentPosition - 1).getTitle(),
songList.get(currentPosition - 1).getPath());
currentPosition = currentPosition - 1;
} else {
attachMusic(songList.get(currentPosition).getTitle(),
songList.get(currentPosition).getPath());
}
} else {
attachMusic(songList.get(currentPosition).getTitle(),
songList.get(currentPosition).getPath());
}
} else {
Toast.makeText(this, "Select a Song . .", Toast.LENGTH_SHORT).show();
}
break;
case R.id.img_btn_next:
if (checkFlag) {
if (currentPosition + 1 < songList.size()) {
attachMusic(songList.get(currentPosition + 1).getTitle(),
songList.get(currentPosition + 1).getPath());

22
currentPosition += 1;
} else {
Toast.makeText(this, "Playlist Ended", Toast.LENGTH_SHORT).show();
}
} else {
Toast.makeText(this, "Select the Song ..", Toast.LENGTH_SHORT).show();
}
break;
case R.id.img_btn_setting:
if (!playContinueFlag) {
playContinueFlag = true;
Toast.makeText(this, "Loop Added", Toast.LENGTH_SHORT).show();
} else {
playContinueFlag = false;
Toast.makeText(this, "Loop Removed", Toast.LENGTH_SHORT).show();
}
break;
}
}

/**
* Function to attach the song to the music player
*
* @param name
* @param path
*/

private void attachMusic(String name, String path) {


imgBtnPlayPause.setImageResource(R.drawable.play_icon);
setTitle(name);
menu.getItem(1).setIcon(R.drawable.favorite_icon);

23
favFlag = true;

try {
mediaPlayer.reset();
mediaPlayer.setDataSource(path);
mediaPlayer.prepare();
setControls();
} catch (Exception e) {
e.printStackTrace();
}
mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
imgBtnPlayPause.setImageResource(R.drawable.play_icon);
if (playContinueFlag) {
if (currentPosition + 1 < songList.size()) {
attachMusic(songList.get(currentPosition + 1).getTitle(),
songList.get(currentPosition + 1).getPath());
currentPosition += 1;
} else {
Toast.makeText(MainActivity.this, "PlayList Ended",
Toast.LENGTH_SHORT).show();
}
}
}
});
}

/**
* Function to set the controls according to the song
*/

24
private void setControls() {
seekbarController.setMax(mediaPlayer.getDuration());
mediaPlayer.start();
playCycle();
checkFlag = true;
if (mediaPlayer.isPlaying()) {
imgBtnPlayPause.setImageResource(R.drawable.pause_icon);
tvTotalTime.setText(getTimeFormatted(mediaPlayer.getDuration()));
}

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

@Override
public void onStartTrackingTouch(SeekBar seekBar) {

@Override
public void onStopTrackingTouch(SeekBar seekBar) {

}
});

25
}

/**
* Function to play the song using a thread
*/
private void playCycle() {
try {
seekbarController.setProgress(mediaPlayer.getCurrentPosition());
tvCurrentTime.setText(getTimeFormatted(mediaPlayer.getCurrentPosition()));
if (mediaPlayer.isPlaying()) {
runnable = new Runnable() {
@Override
public void run() {
playCycle();

}
};
handler.postDelayed(runnable, 100);
}
} catch (Exception e) {
e.printStackTrace();
}
}

private String getTimeFormatted(long milliSeconds) {


String finalTimerString = "";
String secondsString;

//Converting total duration into time


int hours = (int) (milliSeconds / 3600000);
int minutes = (int) (milliSeconds % 3600000) / 60000;

26
int seconds = (int) ((milliSeconds % 3600000) % 60000 / 1000);

// Adding hours if any


if (hours > 0)
finalTimerString = hours + ":";

// Prepending 0 to seconds if it is one digit


if (seconds < 10)
secondsString = "0" + seconds;
else
secondsString = "" + seconds;

finalTimerString = finalTimerString + minutes + ":" + secondsString;

// Return timer String;


return finalTimerString;
}

/**
* Function Overrided to receive the data from the fragment
*
* @param name
* @param path
*/

@Override
public void onDataPass(String name, String path) {
Toast.makeText(this, name, Toast.LENGTH_LONG).show();
attachMusic(name, path);
}

27
@Override
public void getLength(int length) {
this.allSongLength = length;
}

@Override
public void fullSongList(ArrayList<SongsList> songList, int position) {
this.songList = songList;
this.currentPosition = position;
this.playlistFlag = songList.size() == allSongLength;
this.playContinueFlag = !playlistFlag;
}

@Override
public String queryText() {
return searchText.toLowerCase();
}

@Override
public SongsList getSong() {
currentPosition = -1;
return currSong;
}

@Override
public boolean getPlaylistFlag() {
return playlistFlag;
}

@Override

28
public void currentSong(SongsList songsList) {
this.currSong = songsList;
}

@Override
public int getPosition() {
return currentPosition;
}

@Override
protected void onResume() {
super.onResume();
}

@Override
protected void onPause() {
super.onPause();
}

@Override
protected void onDestroy() {
super.onDestroy();
mediaPlayer.release();
handler.removeCallbacks(runnable);
}
}

29
8. Output:

9. Skill developed / Learning out of this Micro-Project:


From this project, we came to know about how a music player is built using Android Studio. In
the objective of doing so, you got to know the features of the music player, its flow, and the
requirements to build it. Further, we saw the things we need to know to get started with the
development of the music player. Finally, we saw the actual implementation of the music player
along with its source code.

10. Applications of this Micro-Project:


1. You can access all the songs present on your device.
2. Play your songs on the go without even having an internet connection.
3. Play or pause your music.

30

You might also like