Search Tutorials

Loading...

Sunday, 20 October 2013

Play mp3 file from Project Folder in Android

In this tutorial, we will learn how to play mp3 file from project folder and here i am simply posted Java code because i am playing a song when activity launch. we can add this code to any widget. just create a new project and open Jave file and past below code:

package coders.hub.com; //you package name

import android.media.MediaPlayer;
import android.os.Bundle;
import android.app.Activity;

public class MainActivity extends Activity {
            @Override
      protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);

//MediaPlayer object is used to play a mp3 file
            MediaPlayer mp;

//copy raj.mp3 in any drawable folder
            mp=MediaPlayer.create(this, R.drawable.raj);

//start to play raj.mp3
            mp.start();
     
      }
 }


Now Run your project...and share this post.

2 comments:

Back to Top