Providing alternate assets to MediaPicker

Roy Posts: 29 🔥

I am trying to configure a custom MediaPicker view to display/load specific assets when using a lens.

Issue is, from what I've tried, the only way to create a SCCameraKitLensMediaPickerProvider is to create the default LensMediaPickerProviderPhotoLibrary.

There is no ability to fully implement a subclass without further information regarding required protocol implementations for functions in LensMediaPickerProviderPhotoLibrary such as loadAndApplyOriginalMediaFromAsset. If i were to implement it, where can i get more info on how to apply resource to lens as a part of this protocol method's job.

- (void)loadAndApplyOriginalMediaFromAsset:(id<SCCameraKitLensMediaPickerAsset>)asset
                                completion:(nullable void (^)(void))completion

I currently have it set up like the CameraKit sample project , and am using a custom MediaPicker to select items for a Lens via app (iOS), as is shown in sample code:

cameraView.mediaPickerView.provider = cameraController.lensMediaProvider
cameraView.mediaPickerView.delegate = cameraController
cameraController.lensMediaProvider.uiDelegate = cameraView.mediaPickerView
/// Media provider for CameraKit.
    public var lensMediaProvider: LensMediaPickerProvider = LensMediaPickerProviderPhotoLibrary(defaultAssetTypes: [.image, .video])
/// Configures the data provider for lenses. Subclasses may override this to customize their data provider.
    /// - Returns: a configured data provider.
    open func configureDataProvider() -> DataProviderComponent {
        // By default, CameraKit will handle data providers (such as device motion),
        // but if you want to handle specific data provider(s), pass them in here, example:
            deviceMotion: nil, userData: UserDataProvider(), lensHint: nil, location: nil,
            mediaPicker: lensMediaProvider)

What is the suggested way to go about solving this? Providing custom media to the MediaPickerView vs using the default Provider?



  • Roy
    Roy Posts: 29 🔥

    Perhaps I found it - could it be this?

    /// Delegate responsible for applying media to a lens. This should not be implemented directly.
    /// @note If you create a custom provider, you'll need to call the methods here from your provider. See notes on
    /// provider.uiDelegate for more details.
    @protocol SCCameraKitLensMediaPickerProviderMediaApplicationDelegate <NSObject>
    /// Notifies lenses that the media picker provider has loaded the full resolution version of an asset and is ready for
    /// it to be applied.
    /// @param provider the provider sending the reequest
    /// @param asset the asset provided by the provider
    /// @param url the URL to a full-resolution image or video for lenses to apply
    /// @param metadata any metadata associated with the asset
    - (void)mediaPickerProvider:(id<SCCameraKitLensMediaPickerProvider>)provider
                                         url:(NSURL *)url
  • Roy
    Roy Posts: 29 🔥

    I've been able to create my own provider class that conforms to LensMediaPickerProvider.

    My last issue now, is to understand how I can create/get a SCCameraKitLensMediaPickerAssetMetadata value/obj to pass to the media picker provider delegate in the provider requestedApplicationOfOriginalAssets method.

    There really isn't too much documentation about it either than this - Definitions/SCCameraKitLensMediaPickerAssetMetadata.html

    Any clue?

  • Roy
    Roy Posts: 29 🔥

    Seem to have found the missing piece - here is the info:

    /// Metadata for a media asset
    typedef struct {
        // If the asset is an image with a face present, a rect specifying the position of the face. Otherwise CGRectZero
        CGRect faceRect;
    } SCCameraKitLensMediaPickerAssetMetadata;

    For my use case, I believe it can be any value.

  • Roy
    Roy Posts: 29 🔥

    Got it to work!

    After some more attempts, I ended up creating a custom lense media provider, and implemented the protocol methods.

    Then, you can pretty much handle things however you want.

    DM me if need help on this!