I have a very simple mediaplayer that play background. It calls file from the apk, but I want it to play from any directory like as music or sdcard.
Here are my codes:
private MediaPlayer mpintro; . . mpintro = MediaPlayer.create(this, R.raw.intro); mpintro.setLooping(true); mpintro.start();
Prepare media file: To play a media file, you need to first prepare it i.e. you need to load the file for playback. Methods used for doing this are prepare(), prepareAsync(), and setDataSource(). Start/Pause the playback: After loading the media file, you can start playing the media file by using the start() method.
One of the most important components of the media framework is the MediaPlayer class. An object of this class can fetch, decode, and play both audio and video with minimal setup.
pause(); On call to start() method, the music will start playing from the beginning. If this method is called again after the pause() method, the music would start playing from where it is left and not from the beginning. In order to start music from the beginning, you have to call reset() method.
It works like this:
mpintro = MediaPlayer.create(this, Uri.parse(Environment.getExternalStorageDirectory().getPath()+ "/Music/intro.mp3")); mpintro.setLooping(true); mpintro.start();
It did not work properly as string filepath...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With