2

I am downloading an mp4 video into a local disk drive from an intranet as the following:

        while ((bufferLength = inputstram.read(buffer)) > 0) {
            fileOutputStream.write(buffer, 0, bufferLength);
            //play(buffer);
            downloadedSize += bufferLength;
            System.out.println("remaining: " + downloadedSize + " out of " + totalSize);
        }

While downloading (after fileOutputStream.write(buffer, 0, bufferLength); statement), I need to play the downloaded buffers in the while loop in exoplayer. How can I do that? I was searching in google and into exoplayer docs but I couldn't find a straight forward answer.

At the moment, I am playing a video in exoplayer as a URL as the following code:

MediaSource videoSource = new ProgressiveMediaSource.Factory(dataSourceFactory)
            .createMediaSource(Uri.parse("http://myhappy_video.mp4"));

So how can I change that to play buffered bytes from input stream as a video?

Khaled
  • 345
  • 5
  • 14
  • I think you mean you want to download and playback at the same time? If so this may help: https://stackoverflow.com/questions/53692452/how-to-download-a-video-while-playing-it-using-exoplayer – Mick Jul 12 '21 at 11:25

1 Answers1

-1

To play a video from http server. You can use DefaultHttpDataSource with DashMediaSource. The following is an example.

// Create a data source factory.
DataSource.Factory dataSourceFactory = new DefaultHttpDataSource.Factory();
// Create a DASH media source pointing to a DASH manifest uri.
MediaSource mediaSource =
    new DashMediaSource.Factory(dataSourceFactory)
        .createMediaSource(MediaItem.fromUri(dashUri));
// Create a player instance.
ExoPlayer player = new ExoPlayer.Builder(context).build();
// Set the media source to be played.
player.setMediaSource(mediaSource);
// Prepare the player.
player.prepare();