The location of media can be specified in two main ways:
- Media Reference
The MediaReference asset allows media to be specified and stored within Unity, media hints to be set (eg transparency and stereo) and referenced easily. This is the preferred way to specify media if the media is permanent.
Alternatively a file path / URL can be specified directly in the MediaPlayer. This is suitable for media that isn't permanent and therefore isn't worth creating a MediaReference for. With this method the media hints need to be specified in the MediaPlayer.
// Opening media via a MediaReference MediaReference mediaReference = _myMediaReference; bool isOpening = mediaPlayer.OpenMedia(mediaReference, autoPlay:true); // Opening media URL via a Path bool isOpening = mediaPlayer.OpenMedia(new MediaPath("https://www.myvideos.com/stream.m3u8", MediaPathType.AbsolutePathOrURL), autoPlay:true); // Opening local file media via a Path bool isOpening = mediaPlayer.OpenMedia(new MediaPath("myvideo.mp4", MediaPathType.RelativeToStreamingAssetsFolder), autoPlay:true); // Changing the media hints for content loaded via Path MediaHints hints = mediaPlayer.FallbackMediaHints; hints.stereoPacking = StereoPacking.TopBottom; mediaPlayer.FallbackMediaHints = hints;
On Android keeping very large video files in the
StreamingAssets folder is not a good idea because this folder is converted into a JAR file and uses a lot of memory to open. In these cases it's best to store the videos in
MediaPathType.RelativeToPersistentDataFolder), usually by downloading it to this folder. You may also need to set the permissions to access this folder which is in
Player Settings > Android > Write Permission > External (SDCard).