API: ShopLive Preview

    API: ShopLive Preview


    Article summary

    You can implement the preview directly through the ShopLivePlayerPreview component provided by Shoplive.

    class ViewController : UIViewController {
        let preview = ShopLivePlayerPreview()
        override func viewDidLoad() { 
            super.viewDidLaod()
            self.view.addSubView(preview)
            preview.translatesAutoresizingMaskIntoConstraints = false
            NSLayoutConstraint.activate([
                preview.topAnchor.constraint(equalTo: self.topAnchor),
                preview.leadingAnchor.constraint(equalTo: self.leadingAnchor),
                preview.trailingAnchor.constraint(equalTo: self.trailingAnchor),
                preview.bottomAnchor.constraint(equalTo: self.bottomAnchor)
            ])
            setPreview()
        }
    
        func setPreview() { 
            preview.action( .initialize ) 
            preview.action( .start(accessKey : "ACCESS_KEY", campaignKey : "CAMPAIGN_KEY", referrer : "REFERRER(optional)")
        }
    }


    Action types

    When calling the commands of the ShopLivePlayerPreview, you can specify them through the .action(.{command}).

    preview.action( .play)
    preview.action( .pause)
    ... 

    Case

    Description

    initialize

    Initializes the information of a ShopLivePlayerPreview object. The following information are initialized.

    • campaignKey, campaignId, shopLiveSessionId, campaignStatus, resizeMode, useCloseButton

    start(accessKey : String campaignKey : String, referrer : String?)

    Loads the player by passing the accessKey and CampaignKey as parameters.

    setMuted(Bool)

    Sets the mute state of the ShopLivePlayerPreview.

    setReferrer(String?)

    Passes a unique identifier that can track the campaign broadcasting as a parameter.

    play

    Plays the campaign as a video.

    pause

    Pauses the campaign

    stop

    Stops the campaign and initializes the player.

    close

    Removes the ShopLivePlayerPreview from the parent view and starts memory release.

    retry

    Retries the campaign.

    setCornerRadius(CGFLoat)

    Sets the cornerRadius of the ShopLivePlayerPreview.

    useCloseButton(Bool)

    Sets whether to enable the Close button of ShopLivePlayerPreview or disable.

    setEnabledVolumeKey(Bool)

    In the ShopLivePlayerPreview, sets whether to enable the event of a volume button on the device.

    setResizeMode(ShopLiveResizeMode)

    Sets the aspect ratio of the video. (Default: ShopLiveResizeMode.CENTER_CROP)


    Result types

    You can subscribe to events that occur in ShopLivePlayerPreview.

    preview.resultHandler = { [weak self] result in 
        switch result { 
            case .log(name : let name, feature : let feature, campaignKey : let campaignKey, payload : let paylaod):
                //handle datas
            .
            .
            .
        }
    
    }

    Case

    Description

    log(name : String, feature : ShopLiveLog.feature, campaignKey : String, payload : [String : Any]?)

    Delivers the event logs of the Shoplive Player. This information is available from analysis tools such as Google Analytics.

    handleReceivedCommand(command : String, payload : [String : Any]?)

    Delivers the information of a command from the Web on the Shoplive iOS SDK.

    avPlayerTimeControlStatus(AVPlayer.TimeControlStatus)

    Delivers the current playback status of the AVPlayer when the ShopLivePlayerPreview changes.

    avPlayerItemStatus(AVPlayerItem.Status)

    Delivers the current status of the AVPlayerItem when the ShopLivePlayerPreview changes.

    requestShowAlertController(UIAlertController)

    Delivers an events when a call to the UIAlertController is required.

    didChangeCampaignStatus(ShopLiveCampaignStatus)

    Delivers the changed broadcasting status when it changes.

    onError(code : String, message : String)

    Delivers a message containing an error situation that occurs before or during a broadcasting.

    onSetUserName(payload : [String : Any]?)

    Called when a user name has changed.

    handleShare(ShopLivePlayerStateData)

    Called when the Share button has been tabbed during the broadcasting. Refer to the following guide for more detailed information of the ShopLivePlayerStateData:

    didChangeCampaignInfo([String:Any]?)

    Delivers the changed information of the current broadcasting.

    didChangeVideoDimension(CGSize)

    Delivers the changed aspect ratio of the ShopLivePlayerPreview.

    handleShopLivePlayerCampaign(ShopLivePlayerCampaign)

    A handler to deliver the information about Shoplive's broadcasting campaign.

    handleShopLivePlayerBrand(ShopLivePlayerBrand)

    A handler to deliver the information about Shoplive's broadcasting brand.


    What's Next