0

In a nutshell, I have a button that should either download audiofile from direct url to the private app cache directory, or (if it was previously done) play that file from cache.

How can I solve it? Could you provide some examples, please?

Justin McGuire
  • 365
  • 1
  • 5
  • 18

1 Answers1

1

First of all you need to download the file and save the path either in a Preference (recommended if you will only have one or just a couple files) or in a database (ideal if a lot of files).

Here you can find a cool guide on how to download a file and save it. Also have a look at this article from the official docs to know better how to save a file properly.

Once you save it you save the path to your file in one of the ways suggested before and play it like this:

MediaPlayer mp = new MediaPlayer();
mp.setDataSource(path);
mp.prepare();
mp.start();

Take a look to this article in the docs for further information.

Community
  • 1
  • 1
Eury Pérez Beltré
  • 2,017
  • 20
  • 28