3

How to cache into disk audio streamed into MediaPlayer? I'd like to use cached audio instead of downloading it each time. Unfortunately setDataSource even do not accepts InputStream, so I don't know solution.. My code:

    mediaPlayer.setDataSource(context, Uri.parse(/* file url */));
    mediaPlayer.prepare();
    mediaPlayer.start();
Taras
  • 507
  • 1
  • 6
  • 17

1 Answers1

0

You can download it to the SDcard (or anywhere) and then play it back using the public void setDataSource (String path) method of MediaPlayer

mediaPlayer.setDataSource(Environment.getExtrnalStorageDirectory() + "/yoursoundfile.mp3");

you may have to tweak the path to get it correct.

http://developer.android.com/reference/android/media/MediaPlayer.html#setDataSource(java.lang.String)

FoamyGuy
  • 46,603
  • 18
  • 125
  • 156
  • Thanks, I'll try. And it will be possible even play file simultaneously with it's download process? – Taras Nov 10 '12 at 15:12