Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple mediaplayer play mp3 from file path?

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(); 
like image 411
John simit Avatar asked May 23 '13 13:05

John simit


People also ask

How Audio files can be play through Media Player?

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.

What class in Android can play audio?

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.

Which method of the MediaPlayer class allows you to read a music file from a given point in time rather than from the beginning of the song )?

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.


1 Answers

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...

like image 114
John simit Avatar answered Oct 05 '22 23:10

John simit