Providing alternate assets to MediaPicker
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.
//SCCameraKitLensMediaPickerProvider.h - (void)loadAndApplyOriginalMediaFromAsset:(id<SCCameraKitLensMediaPickerAsset>)asset completion:(nullable void (^)(void))completion NS_SWIFT_NAME(loadAndApplyOriginalMedia(from: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:
//CameraViewController.swift cameraView.mediaPickerView.provider = cameraController.lensMediaProvider cameraView.mediaPickerView.delegate = cameraController cameraController.lensMediaProvider.uiDelegate = cameraView.mediaPickerView
//CameraController.swift /// 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: DataProviderComponent( 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?
Thanks!
Comments
-
Perhaps I found it - could it be this?
NS_SWIFT_NAME(LensMediaPickerProviderMediaApplicationDelegate) /// 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 requestedApplicationOfOriginalAssets:(id<SCCameraKitLensMediaPickerAsset>)asset url:(NSURL *)url metadata:(SCCameraKitLensMediaPickerAssetMetadata)metadata; @end
1 -
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 theprovider requestedApplicationOfOriginalAssets
method.There really isn't too much documentation about it either than this -
https://kit.snapchat.com/reference/CameraKit/ios/1.13.0/SCSDKCameraKit/Type Definitions/SCCameraKitLensMediaPickerAssetMetadata.htmlAny clue?
1 -
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.
0 -
Hi, I know it's been two years since this but was wondering if you could help me. Don't know how to DM here sorry
I'm trying to apply the green screen template lens in my app and effectively select an image with the media picker for the background without success.
We have it set up so the provider uses the default picker handled by the SDK. I can apply the lens, but the picker is not shown. I also saw the template has a tap detection script to hide/show the media picker but nothing happens on my app when tapping.
Do you know if there's a way to achieve this? Do I need to implement something more custom as you did?
Thanks!
0