Android Media Player: Download to File and Stream From File

media player android studio
android media player library
android mediaplayer streaming example
android media player app
how to play audio file in android programmatically
android-mediaplayer service example
android mediaplayer video example
audio streaming in android programmatically

I'm using Android's MediaPlayer to play MP3 files that are simultaneously downloaded from the internet using the DownloadManager. I'm aware of the MediaPlayer's capability to stream directly, but I don't want to use that:

The obvious advantage you get by downloading and simultaneously streaming from file is that this way, the file gets stored and is available locally afterwards.

  • This works in principle - the MediaPlayer starts to play the file even if it not fully downloaded. (BTW my problem is NOT that I can't get MediaPlayer to play.)
  • The problem is that when the MediaPlayer gets to the position where the download status just was when it started playing, it stops and calls onCompletion. (Clarification: Let's assume the file is 12% downloaded when I start playing. When the player gets to the position at 12%, it stops.)
  • Quick side note: OnBufferingUpdateListener.onBufferingUpdate(...) is not called when something is appended to the MP3 file via the DownloadManager.

So the question is: How can I simultaneously download an audio file to the file system and play it? (Android 4+ suffices, if that makes a difference.)


I assume you're pointing MediaPlayer to the file. In that case I don't think it supports streaming, and it probably checks the size of the file and such in advance, so it won't update itself as more of the file comes in.

You have to point it to a content source that will work with streaming, e.g. HTTP. I've just checked how "ES File Explorer" does it (Using LogCat) - when you click on a video file in a remote file share, it opens an local HTTP server, and sends to the MediaPlayer an HTTP Uri to its local server, that also includes the remote path.

When it gets the request through HTTP, the local server starts reading the file from the remote location, and providing it locally to MediaPlayer through HTTP. You can probably do the same, and in addition to providing it via HTTP also save it to disk.

MediaPlayer overview, audio files. We looked around and found the best media player apps for Android! 10 best music streaming apps and music streaming services for Android! Joe Hindy 2 To be fair, most file browsers have the ability to play video or audio content. VLC is one of the most popular Android media players. I'm using Android's MediaPlayer to play MP3 files that are simultaneously downloaded from the internet using the DownloadManager.I'm aware of the MediaPlayer's capability to stream directly, but I don't want to use that:


It helped me, I hope to help someone else.

Player download & play music.

mMediaPlayer.setDataSource(DOWNLOAD_URL);

   File root = Environment.getExternalStorageDirectory();
   File dir = new File(root + "/Folder");
   if (!dir.exists()) {
        dir.mkdirs();

DownloadManager downloadManager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
            Uri downloadUri = Uri.parse(DOWNLOAD_URL);
            DownloadManager.Request request = new DownloadManager.Request(downloadUri);
            request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_MOBILE | DownloadManager.Request.NETWORK_WIFI);
            request.setAllowedOverRoaming(false);
            request.setTitle(TITLE);
            request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
            request.setDestinationInExternalPublicDir(Environment.DIRECTORY_MUSIC, TITLE);
            request.allowScanningByMediaScanner();

After downloading file:

mMediaPlayer.setDataSource(Environment.getExternalStorageDirectory() + "/Folder/" + TITLE + ".mp3");

5 best media player apps for Android to play both video and music files, Simple steps to download online videos to your computer from video streaming websites. Using VLC you can save the file in your PC for ease of access. Media Player is a Universa Video Player for Android, you can easily play any video files with the media player. The Media Player can handle all popular video and music formats including: mp3, mp4


Download Online Video Using VLC Media Player, All codecs are included with no separate downloads. This is the port of VLC media player to the Android™ platform. VLC for Android can play any video and audio files, as well as network streams, network shares and drives, and DVD ISOs,  VLC for Android can play any video and audio files, as well as network streams, network shares and drives, and DVD ISOs, like the desktop version of VLC. VLC for Android is a full audio player,


VLC for Android, From now on, when you want to view or stream media files on your PC, just open the Virus Free Download Music Player app for Android. Conversion usually implies video quality loss unless there's no transcoding, so you can play your media truly losslessly. VLC for Android may not have the prettiest interface, but no app comes close to it in terms of player versatility. It even has the more advanced features that VLC for PC has, like Network Streaming and more.


Network music player android, When a video appears in feed, the app first downloads the whole video file to the stream the video to the MediaPlayer as the video file is being downloaded. One Player - A simple, yet effective video player. It comes with advanced hardware acceleration and subtitle support. Enjoy the easy and convenient free player on mobile with One Player. Download now for free a great player which will help you enjoy music, movies, and TV shows like never before with many features:


Improving Video Playback on Android, So, by using MediaPlayer APIs, you can play audio/video files from or play files from your Application's resource file or even you can stream  Media Player for Android features: Automatic detection of media on the SD card Unified start screen to access audio or video files and playing internet radio or e-radio Intuitive playlist creation and editing Intelligent play button Audio meta data (artist, album, year) information Easy Insert mode for adding songs to a playlist Advanced play controls like 'swipe to seek' Ability to set