How to play the audio files directly from res/raw folder?
try this for playing from raw ::
MediaPlayer mPlayer2;
mPlayer2= MediaPlayer.create(this, R.raw.bg_music_wav);
mPlayer2.start();
permission in manifest file ::
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
Update::
public void onItemClick(AdapterView<?> arg0, View view, int position,long id) {
MediaPlayer mPlayer2;
if(position==1)
{
mPlayer2= MediaPlayer.create(this, R.raw.song1);
mPlayer2.start();
}else it() .....
}
add this code in onItemClickListener.
listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View view, int position,long id) {
TextView txtView=(TextView)view.findViewById(R.id.txt_view);
String fname=txtView.getText().toString().toLowerCase();
int resID=getResources().getIdentifier(fname, "raw", getPackageName());
MediaPlayer mediaPlayer=MediaPlayer.create(this,resID);
mediaPlayer.start();
}
});
mVideoView = (VideoView) findViewById(R.id.Video_FrontPage);
uri = Uri.parse("android.resource://com.urPackageName/" + R.raw.welcom_video);
mVideoView.setVideoURI(uri);
mVideoView.setMediaController(new MediaController(this));
mVideoView.requestFocus();
mVideoView.start();