Course Content

If you are facing any issue in playing video please use Firefox browser.

Course Content

Description

Create Music Player in Android Application

 

In this video we are going to create Music player in Android application.

For that we need to have one audio, which we will save inside our 'assets' folder in mp3 format.

After that will design its layout, for that which we have taken linearlayout and in it we have three different buttons. One to play, other to pause, and another to stop.

Now to design our main music player we will go to 'musicplayer.java' file and inside that we have taken one textview 't' and define three buttons. After that we need to create an instance for media player 'mp' and filedescriptor 'sfd'.

Now we will design a code to read the music file which we have stored in our assets folder.

void Source

{

try

{

sdf=getAssests().openFd("File_name.mp3").getFileDescriptor();

mp.setdatasource(sfd);

mp.prepare();

}

catch (IOException e)

{

e.printStackTrace();

}

}

void play()

{

mp.start();

}

void stop()

{

mp.stop();

mp.reset();

source();

}

Now we will design click event for three different buttons, in which we will call the the events which we define for their respective buttons.

After that we will run the code, and see that it is working accurately and the music player starts to play music when used with 'Play' button.

FAQs

Recommended Courses

Share With Friend

Have a friend to whom you would want to share this course?

Download The Apps

Code Scan or Download the app
Google Play Store
297K+ Downloads
4.5 Rating
10K+ Reviews
  • Learn anywhere on the go
  • Get regular updates about your enrolled or new courses
  • Share content with your friends
  • Evaluate your progress through practice tests
  • No internet connection needed
  • Enroll for the webinar and join at the time of the webinar from anywhere