This feature provides a way to get images from camera or from device photo gallery/album. You need to specify the source which is
Camera or
Album or
Both Camera & Album
Additionally, you can provide a scaling factor for your picking image as well.
// Set popover to last touch position on iOS. This has no effect on Android.NPBinding.UI.SetPopoverPointAtLastTouchPosition();// Pick imageNPBinding.MediaLibrary.PickImage(eImageSource.ALBUM, SCALE_FACTOR_VALUE, PickImageFinished);
In the above code, we are just setting the popover point on iOS to last touch position and picking from Album source.
iOS by default allow to apply crop action. If you want to disable it, just call NPBinding.MediaLibrary.SetAllowsImageEditing(false); before calling pick image action.
Once the image is selected, passed scale value is applied and PickImageFinished will get called providing the texture.
//Callbackprivate void PickImageFinished (ePickImageFinishReason _reason, Texture2D _image){Debug.Log("Reason = " + _reason);Debug.Log("Texture = " + _image);}
Save an image file/texture/screenshot to gallery and get a callback once finished.
NPBinding.MediaLibrary.SaveScreenshotToGallery(SaveImageToGalleryFinished);
NPBinding.MediaLibrary.SaveImageToGallery(_textureInstance, SaveImageToGalleryFinished);
NPBinding.MediaLibrary.SaveImageToGallery(URL.FileURLWithPath(FILE_PATH), SaveImageToGalleryFinished);
private void SaveImageToGalleryFinished (bool _saved){Debug.Log("Saved image to gallery successfully ? " + _saved);}
Videos can be played from
URL/Streaming (ex: http://www.yourwebsite.com/test.mp4, http://www.yourwebsite.com/test.avi)
Local Storage (File Path)
Embed Html
Youtube Videos
Android has a restriction of allowed file size if assets are in streaming assets. So, its recommended to copy your files to Application.PersistentPath and pass the file path.
If video is successfully played, it ruturns a callback with ePlayVideoFinishReason.PLAYBACK_ENDED status. In-case of any error ePlayVideoFinishReason.PLAYBACK_ERROR is returned.
NPBinding.MediaLibrary.PlayYoutubeVideo(YOUTUBE_VIDEO_ID, PlayVideoFinished);
You need to pass video id to play the video.
On Android, if you set the youtube API key, it will use the Youtube SDK internally to play the video.
NPBinding.MediaLibrary.PlayVideoFromURL(URL.URLWithString(VIDEO_URL), PlayVideoFinished);
VIDEO URL : This can be either a network URL or local storage file path.
NPBinding.MediaLibrary.PlayVideoFromGallery(PickVideoFinished, PlayVideoFinished);
This provides two callbacks one triggered once the selection of video is done and another after video is finished playing.
NPBinding.MediaLibrary.PlayEmbeddedVideo(m_embedHTMLString, PlayVideoFinished);
Check demo scene for how to write a sample embed HTML for playing a video.
private void PlayVideoFinished (ePlayVideoFinishReason _reason){Debug.Log("Finished playing video. Reason = " + _reason);}
Finish reason can be either
ePlayVideoFinishReason.PLAYBACK_ENDED or
ePlayVideoFinishReason.PLAYBACK_ERROR
​​
​