Usage
Once you have enabled the required features that you are going to use in Media Services, you can start using the API by importing the namespaces.
Once after importing the namespace, all features within Media Services can be accessed through MediaServices class.
Overview
Media Services provides mainly three functionalities
Select media
Capture media
Save media
All the functionality api methods have below similarities designed for ease of use.
All methods takes options to configure the functionality further.
If there is a data thats returned in the callback, it will be of IMediaContent.
If the action needs a permission, the permission is displayed as required to the user.
IMediaContent is an interface to wrap the media content thats received from an api call. Once you have IMediaContent instance you can do any of the below
Fetch the content as a Texture2D (if it's an image)
Fetch the content as a file (you can even provide the save directory and file name)
Fetch the content as a raw data for further processing (RawMediaData)
Select Media Content
For selected any media from device, we need to pass MediaContentSelectOptions instance SelectMediaContent method call.
Through options you can
Set the title that needs to be displayed(if any) when selecting the content
Set mime type of the content that needs to be selected
Set max allowed images to select
Options can be created as follows
You can make use of MediaContentSelectOptions utility methods if you have a direct use-case for image or video or audio
Once after creating MediaContentSelectOptions instance, call MediaServices.SelectMediaContent with the options and a callback which gets called after the action is complete.
If a permission is required to select media of the user, the first call presents the permission request as required.
Capture Media Content
To capture content from camera whether it could be image or video, MediaContentCaptureOptions instance need to be passed to CaptureMediaContent.
Through options you can
Set the title that needs to be displayed(if any) when selecting the content
Set file name(without extension) of the captured file
Set capture content type is image or video
Options can be created as follows
You can make use of MediaContentCaptureOptions utility methods if you have a direct use-case for image or video
Once after creating MediaContentCaptureOptions instance, call MediaServices.CaptureMediaContent with the options and a callback which gets called after the action is complete.
Save Media Content
To save media content to device whether it could be image or video or any other media, MediaContentSavesOptions instance need to be passed to SaveMediaContent.
Through options you can
Set directory or album name for target
Set file name(without extension) of the file being saved
Options can be created as follows
Once after creating MediaContentSavesOptions instance, call MediaServices.SaveMediaContent with the options and a callback which gets called after the action is complete.
Plugin handles the permissions as required automatically and selects the platform recommended ways to implement the functionality.
For ex: Photo Picker is considered for images on Android as it avoids permissions and recommended way by google.
Similarly on iOS PHPhotoPicker is preferred for images and document picker as a fallback for other contents.
Last updated