Cross Platform Native Plugins
A true cross platform tool for Unity which provides unique and unified way to access native functionality on mobile platforms.
Public Member Functions | List of all members
MediaLibrary Class Reference

Provides cross-platform interface to access devices's media gallery and camera for picking images and playing videos. More...

Public Member Functions

virtual bool IsCameraSupported ()
 Determines whether the device supports picking image using camera. More...
 
virtual void SetAllowsImageEditing (bool _value)
 Sets the value indicating whether the user is allowed to edit a selected image. More...
 
virtual void PickImage (eImageSource _source, float _scaleFactor, PickImageCompletion _onCompletion)
 Opens an user interface to pick an image from specified image source. More...
 
void SaveScreenshotToGallery (SaveImageToGalleryCompletion _onCompletion)
 Captures a screenshot and saves it to device's media gallery. More...
 
void SaveImageToGallery (URL _URL, SaveImageToGalleryCompletion _onCompletion)
 Saves specifed file to device's media gallery. More...
 
void SaveImageToGallery (Texture2D _texture, SaveImageToGalleryCompletion _onCompletion)
 Saves specifed texture to device's media gallery. More...
 
virtual void SaveImageToGallery (byte[] _imageByteArray, SaveImageToGalleryCompletion _onCompletion)
 Saves specifed image data to device's media gallery. More...
 
virtual void PlayYoutubeVideo (string _videoID, PlayVideoCompletion _onCompletion)
 Plays a full-screen Youtube video. More...
 
virtual void PlayEmbeddedVideo (string _embedHTMLString, PlayVideoCompletion _onCompletion)
 Plays a full-screen video using native WebView. More...
 
virtual void PlayVideoFromURL (URL _URL, PlayVideoCompletion _onCompletion)
 Plays a full-screen video from specified URL. This URL can point to local/remote file. More...
 
virtual void PlayVideoFromGallery (PickVideoCompletion _onPickVideoCompletion, PlayVideoCompletion _onPlayVideoCompletion)
 Plays a full-screen video selected from device's video gallery. More...
 
delegate void PickImageCompletion (ePickImageFinishReason _reason, Texture2D _image)
 Delegate that will be called when image picker view is dismissed. More...
 
delegate void SaveImageToGalleryCompletion (bool _success)
 Delegate that will be called when specified image is saved to gallery. More...
 
delegate void PickVideoCompletion (ePickVideoFinishReason _reason)
 Delegate that will be called when video picker view is dismissed. More...
 
delegate void PlayVideoCompletion (ePlayVideoFinishReason _reason)
 Delegate that will be called when video playback ended. More...
 

Detailed Description

Provides cross-platform interface to access devices's media gallery and camera for picking images and playing videos.

Member Function Documentation

virtual bool IsCameraSupported ( )
virtual

Determines whether the device supports picking image using camera.

Returns
true if the device supports picking image using camera; otherwise, false.
virtual void SetAllowsImageEditing ( bool  _value)
virtual

Sets the value indicating whether the user is allowed to edit a selected image.

Parameters
_valueThe value to set.

This property is set to true by default.

virtual void PickImage ( eImageSource  _source,
float  _scaleFactor,
PickImageCompletion  _onCompletion 
)
virtual

Opens an user interface to pick an image from specified image source.

Parameters
_sourceThe source to use to pick an image.
_scaleFactorThe factor used to rescale selected image. Having value as 1.0f returns the image without any modification.
_onCompletionCallback that will be called after operation is completed.
void SaveScreenshotToGallery ( SaveImageToGalleryCompletion  _onCompletion)

Captures a screenshot and saves it to device's media gallery.

Parameters
_onCompletionCallback that will be called after operation is completed.
void SaveImageToGallery ( URL  _URL,
SaveImageToGalleryCompletion  _onCompletion 
)

Saves specifed file to device's media gallery.

Parameters
_URLThe URL points to the file saved in local/remote path.
_onCompletionCallback that will be called after operation is completed.
Note
Use absolute path if specified URL points to a local file. And needless to say, assign proper file path as the file structure will differ with platform.
void SaveImageToGallery ( Texture2D  _texture,
SaveImageToGalleryCompletion  _onCompletion 
)

Saves specifed texture to device's media gallery.

Parameters
_textureUnity texture object to be saved.
_onCompletionCallback that will be called after operation is completed.
virtual void SaveImageToGallery ( byte[]  _imageByteArray,
SaveImageToGalleryCompletion  _onCompletion 
)
virtual

Saves specifed image data to device's media gallery.

Parameters
_imageByteArrayRaw form of image to be saved.
_onCompletionCallback that will be called after operation is completed.
virtual void PlayYoutubeVideo ( string  _videoID,
PlayVideoCompletion  _onCompletion 
)
virtual

Plays a full-screen Youtube video.

Parameters
_videoIDA string used to identify Youtube video.
_onCompletionCallback that will be called after operation is completed.
virtual void PlayEmbeddedVideo ( string  _embedHTMLString,
PlayVideoCompletion  _onCompletion 
)
virtual

Plays a full-screen video using native WebView.

Parameters
_embedHTMLStringEmbedded HTML string that is loaded into WebView for playing video.
_onCompletionCallback that will be called after operation is completed.
virtual void PlayVideoFromURL ( URL  _URL,
PlayVideoCompletion  _onCompletion 
)
virtual

Plays a full-screen video from specified URL. This URL can point to local/remote file.

Parameters
_URLURL of the video to play.
_onCompletionCallback that will be called after operation is completed.
Note
Given URL should point directly to the video. Eg: http://www.voxelbusters.com/movie.mp4
virtual void PlayVideoFromGallery ( PickVideoCompletion  _onPickVideoCompletion,
PlayVideoCompletion  _onPlayVideoCompletion 
)
virtual

Plays a full-screen video selected from device's video gallery.

Parameters
_onPickVideoCompletionCallback that will be called after video is picked from gallery.
_onPlayVideoCompletionCallback that will be called after video playback ended.
delegate void PickImageCompletion ( ePickImageFinishReason  _reason,
Texture2D  _image 
)

Delegate that will be called when image picker view is dismissed.

Parameters
_reasonThe reason that caused the view to dismiss.
_imageThe image selected from specified eImageSource.
delegate void SaveImageToGalleryCompletion ( bool  _success)

Delegate that will be called when specified image is saved to gallery.

Parameters
_successA bool value used to indicate operation status.
delegate void PickVideoCompletion ( ePickVideoFinishReason  _reason)

Delegate that will be called when video picker view is dismissed.

Parameters
_reasonThe reason that caused the view to dismiss.
delegate void PlayVideoCompletion ( ePlayVideoFinishReason  _reason)

Delegate that will be called when video playback ended.

Parameters
_reasonThe reason for playback end.