Playing a media file and adding it at the same time

I am developing a media player that should be able to play audio from the Internet. As I already noted, the standard MediaPlayer rather unstable when playing remote content: it often crashes or stops playing for no reason. On the other hand, I want to implement multimedia caching. But I did not find a way to get buffered content from MediaPlayer to save it somewhere on the device.

So, I would like to implement buffering for myself and make MediaPlayer play only local media. The first way that I see is to upload a sufficient number of media files to a file, start playing this file using MediaPlayer and continue downloading the rest of the media file (with a pause when the media file is not loaded enough and other similar events are processed).

The question is, can I play the file and add it at the same time? Now I have IllegalStateExceptions when calling MediaPlayer setDataSource

UPD

IllegalStateException was IllegalStateException by invalid logic. MediaPlayer is playing now.

But another problem arose.

So, the first 5% of the tracks load, MediaPlayer starts playing, plays those 5%, and then stops. Is this a way to keep playing?

Starting playback is trivial:

 private void startPlayback(final File file) { try { FileInputStream fs = new FileInputStream(file); mPlayer.setDataSource(fs.getFD()); mPlayer.prepare(); mPlayer.start(); } catch (IOException e) { Log.e(e); } } 

Maybe a different type of stream is useful for this case?

+2
android android-mediaplayer
source share
1 answer

The simultaneous addition and playback of files works on some devices and does not work on others. So this is not a solution. I tried many ways to implement my own buffering and playback (see Best practices for streaming audio ) and decided to use the JellyBean Media API (as I develop for a JB device). For devices with preliminary JB, this question remains open

0
source share

All Articles