views:

24

answers:

1

Hi All!

Can someone please point to me what is wrong with my code?

try{
MediaPlayer p = new MediaPlayer();
p.setDataSource(getCacheDir() + "/temp.mp3");
p.prepare();
p.start();
}catch(Exception e){}

MediaPlayer p catches Exception whenever it calls prepare(). File temp.mp3 is already inside the cache folder and it is not corrupt or what so ever but it doesn't get played. Is it that MediaPlayer can't play files on cache?

I hope someone can give me an idea of what I have done wrong. Thanks in advance!

+1  A: 

Probably cache dir is your private dir and media player can't access it. Try to play from SD card.

Fedor
Yeah, I just known that my Cache dir can't be accessed right away. I have to use Filedescriptor for that and it works like a charm. Thanks for the tip.
junmats