Search code examples
androidandroid-mediaplayerhttp-streamingandroid-videoviewprogressive-download

Android - Is it possible to access media files locally after they have been watched with VideoView and Mediacontroller?


I am using a MediaController and a VideoView to show videos that I am streaming via HTTP from Amazon S3.

I want to make the video files accessible offline after hey have been watched for the first time. The streaming works well, my question is where does Android save the video files and are they actually accessible once the video has been completely watched (and thus must haben completely downloaded).

The documentation of both classes doesn't provide any details on this issue, neither if the media files are stored, nor where they would be stored. It feels like this would be a great task for the MediaController, but really nowhere I found any hints on this.

My solution would now be to use an instance of DownloadManager, that is downloading the file in parallel while streaming, but this feels very, very wrong!


Solution

  • The VideoView in Android uses the MediaPlayer API which in case of a remote media will stream it and decode it/render it on screen on the fly.

    The MediaPlayer is not going to store anything on the device's flash, rather, it will use a circular buffer in memory which is used as a preprocessing cache. More info on this is available in the source code of NuCacheSource2 implementation.

    Now, what you could do to solve your problem is to write a proxy that will run on your device or elsewhere you want to save the media. While downloading the remote media, it will be able to save it on a file system while forwarding the data to Android's MediaPlayer. In this case you will need to provide the MediaPlayer with a URL pointing to your proxy rather to the original location at which lives the remote media.