Monday 4 April 2011

Playing Audio File from Raw Resources

We'll share some info on how to play audio or video which can be stored in application's resource folder (res > raw).


Step 1: Put the audio/video file in (res/raw) folder of your project. If the "raw" folder does not exist, create one.
Step 2: Put in the following code:-


Private MediaPlayer mp;

mp = MediaPlayer.create(this, R.raw.audiofilename);
                    mp.setLooping(true);
                    mp.start();

Note:-
1. Change the audiofilename according to your own audio file name.
2. When you mp.setLooping(true), the audio file will play continuosly until you stop it.

Roger,
mytikus

1 comment:

Anonymous said...

this is wrong,first start(),and then loop.