Index: Sr. No. Page No
Index: Sr. No. Page No
1 3.Proposed Methodology 2
5. Resources Required 4
1.Rationale 4
8. Output 30
1
Annexure I
Micro Project Proposal
Develop a Music Player using Java and XML in Android
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:
3
5. Resources Required:
3 Browser Chrome 1
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.
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.
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.
3 Browser Chrome 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">
</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 {
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
*/
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);
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.
*/
/**
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
*/
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();
}
}
26
int seconds = (int) ((milliSeconds % 3600000) % 60000 / 1000);
/**
* 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:
30