Search Tutorials

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.

5 comments:

  1. getting so many errors

    ReplyDelete
    Replies
    1. :( post your code here. hope fully I will guide you.

      Delete
  2. getting so many errors

    ReplyDelete
    Replies
    1. may you use code in existing project, I suggest while you test the code from websites, kindly create a new project and then use it in your application.

      Delete
  3. This comment has been removed by the author.

    ReplyDelete

Back to Top