Can I upload mp3 files to the cloud and play them using the media player? How to specify an appeal to the link. THANK!

  • In datasors insert Uri File from the link, and that's it. I don’t understand why you can’t find the answer to this question in Google? 23 seconds is enough for you - Vladyslav Matviienko

1 answer 1

String url = "http://..."; // your URL here MediaPlayer mediaPlayer = new MediaPlayer(); mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); mediaPlayer.setDataSource(url); mediaPlayer.prepareAsync(); //You can show progress dialog here untill it prepared to play mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() { @Override public void onPrepared(MediaPlayer mp) { //Now dismis progress dialog, Media palyer will start playing mp.start(); } }); mediaPlayer.setOnErrorListener(new MediaPlayer.OnErrorListener() { @Override public boolean onError(MediaPlayer mp, int what, int extra) { // dissmiss progress bar here. It will come here when MediaPlayer // is not able to play file. You can show error message to user return false; } }); 

UPD:

 int index = 0; public void play(MediaPlayer player, String url) { try { player.reset(); player.setDataSource(url); player.prepareAsync(); } catch (IOException e) { e.printStackTrace(); } } final ArrayList<String> urls = new ArrayList<>(); urls.add("..."); urls.add("..."); urls.add("..."); MediaPlayer mediaPlayer = new MediaPlayer(); mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); play(mediaPlayer, urls.get(index)); //You can show progress dialog here untill it prepared to play mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() { @Override public void onPrepared(MediaPlayer mp) { //Now dismis progress dialog, Media palyer will start playing mp.start(); } }); mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { @Override public void onCompletion(MediaPlayer mediaPlayer) { index++; if (index < urls.size()) { play(mediaPlayer, urls.get(index)); } } }); mediaPlayer.setOnErrorListener(new MediaPlayer.OnErrorListener() { @Override public boolean onError(MediaPlayer mp, int what, int extra) { // dissmiss progress bar here. It will come here when MediaPlayer // is not able to play file. You can show error message to user return false; } }); 
  • What if there are a lot of files? - Muhammadnakshubandi Lobster
  • @ Muhammadnakshubandi Omarov, set OnCompletionListener, which works when the file finishes playing, and call reset (), setDataSource, and prepare () again, but with another link - katso
  • Do not make a job to write an example? Nika can't figure it out (( - Muhammadnakshubandi Omarov
  • I honestly do not know what you get from the fact that the answer to the question. But I am ready to send you a small reward. I'm not suffering the first day with this. Novice and I do not understand - Muhammadnakshubandi Lobsters
  • @ Muhammadnakshubandi Omarov , updated the answer - katso