Implementing Feature

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.
// Pick image
NPBinding.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.

Note : iOS Platform

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.

private 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.SaveImageToGallery(_textureInstance, SaveImageToGalleryFinished);
NPBinding.MediaLibrary.SaveImageToGallery(URL.FileURLWithPath(FILE_PATH), SaveImageToGalleryFinished);

Callback Implementation

private void SaveImageToGalleryFinished (bool _saved)
Debug.Log("Saved image to gallery successfully ? " + _saved);

Videos can be played from

Note : Android Platform

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.

Play Youtube Video

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.

Play from URL

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.

Play from embedded HTML string

NPBinding.MediaLibrary.PlayEmbeddedVideo(m_embedHTMLString, PlayVideoFinished);

Check demo scene for how to write a sample embed HTML for playing a video.

Callback Implementation

private void PlayVideoFinished (ePlayVideoFinishReason _reason)
Debug.Log("Finished playing video. Reason = " + _reason);

Finish reason can be either

  • ePlayVideoFinishReason.PLAYBACK_ENDED or

  • ePlayVideoFinishReason.PLAYBACK_ERROR

Video Playback on iOSVideo Playback on Android