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:
Now Run your project...and share this post.
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.activi ty_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.
getting so many errors
ReplyDelete:( post your code here. hope fully I will guide you.
Deletegetting so many errors
ReplyDeletemay 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.
DeleteThis comment has been removed by the author.
ReplyDelete