- Print
API: ShopLive Preview
- Print
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
|
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 |
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 |
retry | Retries the campaign. |
setCornerRadius(CGFLoat) | Sets the cornerRadius of the |
useCloseButton(Bool) | Sets whether to enable the Close button of |
setEnabledVolumeKey(Bool) | In the |
setResizeMode(ShopLiveResizeMode) | Sets the aspect ratio of the video. (Default: |
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 data
.
.
.
}
}
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 |
avPlayerItemStatus(AVPlayerItem.Status) | Delivers the current status of the |
requestShowAlertController(UIAlertController) | Delivers an events when a call to the |
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
|
didChangeCampaignInfo([String:Any]?) | Delivers the changed information of the current broadcasting. |
didChangeVideoDimension(CGSize) | Delivers the changed aspect ratio of the |
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.
|