0
var medPlay: MediaPlayer
holder.vidPlayer.setVideoPath(fileUrl)
holder.vidPlayer.setOnPreparedListener { mp ->
    medPlay = mp
}

Instead of downloading the Video separately again for sharing, I'd like to share the file that is already loaded in the VideoView / MediaPlayer and then:

Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setType("video/*");
sharingIntent.putExtra(Intent.EXTRA_TEXT, "Hey this is the video text");
sharingIntent.putExtra(Intent.EXTRA_STREAM,uriFromVideoView);
startActivity(Intent.createChooser(sharingIntent,"Share Video");

Is that possible? I would also accept alternatives / suggestions

Eduard Unruh
  • 985
  • 1
  • 14
  • 35

1 Answers1

0

Is that possible?

No. For starters, it is not physically possible for all types of streams. Beyond that, VideoView/MediaPlayer are not writing the media to disk. They download in chunks, to minimize RAM consumption, and use it solely for playback.

I would also accept alternatives / suggestions

Download the video yourself, such as by using OkHttp. Use the downloaded copy both for setVideoPath() and for ACTION_SEND (the latter by way of FileProvider, most likely). Note that this will only work for video streams that are actual files (e.g., not some livestream), and it would require downloading the entire video first.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • @EduardUnruh: "It really suck that android doesn't offer the option to save the video in ram" -- in many cases, it would not fit. Moreover, whatever caching that `MediaPlayer` does would not necessarily have to be something that you can access independently, in a way that represents an entire file that could be shared with another app. If you want to be able to share the content, you need to obtain the full content yourself. – CommonsWare Jul 05 '21 at 21:59