-1

MediaPlayer cannot use the InputStream as DataSource. what I want is I can reduce or discard the MediaPlayer prepared time, so I need cache the stream to a file. When the target Sdk >= 23, I can Use

mMediaPlayer.setDataSource(new MediaDataSource() {
        @Override
        public int readAt(long position, byte[] buffer, int offset, int size) throws IOException {
            return 0;
        }

        @Override
        public long getSize() throws IOException {
            return 0;
        }

        @Override
        public void close() throws IOException {

        }
    });

but how to make it work at the lower target. Now, I have researched two ways:

1:Just like NanoHttp cache stream , build a local server, convert the remote url to local url, and use setDataSource(localUri)

2:Cache the video head to a local file, but the FileDescriptor cannot be read over the writing time. There are other data structure could be read and write meanwhile?

Do you have better idea?

Could anybody help me ?

Stone305585
  • 101
  • 1
  • 10

1 Answers1

1

I recommend you to use ExoPlayer instead of using Android MediaPlayer, because MediaPlayer has some issues in streaming videos.

If you want to use a library simpler than ExoPlayer you can use ExoMedia instead.

Milad Yarmohammadi
  • 1,253
  • 2
  • 22
  • 37