Using ShoplivePreview
- Print
Using ShoplivePreview
- Print
Article summary
Did you find this summary helpful?
Thank you for your feedback!
Implement the app’s live preview
You can directly implement the preview using the ShopLivePreview provided by the Shoplive SDK .
activity.xml
// If only one of width or height is written, it is flexible.
<cloud.shoplive.sdk.ShopLivePreview
android:id="@+id/preview"
android:layout_width="something dimens"
android:layout_height="something dimens" /> preview.start(“{accessKey}”, “{campaignKey}”)
preview.setOnClickListener {
// Preview transition animation
ShopLive.setPreviewTransitionAnimation(requireActivity(), binding.preview)
ShopLive.play(requireActivity(), campaignKey)
preview.release()
}
// For lifecycle observing preview
preview.setLifecycleObserver(this.viewLifecycleOwner) Playing preview with sound
A preview starts muted by default (isMuted = true). Turn the mute off to play with sound from the start.
Popup preview — ShopLive.showPreviewPopup
ShopLive.showPreviewPopup(
activity,
ShopLivePreviewData(campaignKey).apply {
// Defaults to true (muted). Set false to play with sound from the start.
isMuted = false
// Set this as well to let the user control mute with the volume keys. Defaults to false.
isEnabledVolumeKey = true
}
)Inline preview — when you place ShopLivePreview in your layout
preview.setMuted(false)
preview.setEnabledVolumeKey(true) // optionalEven with mute turned off, no sound plays if the broadcast video itself has no audio. If you hear nothing, check whether that broadcast has an audio track first.
Control swipe gesture
You can exit the preview by swiping using the ShopLiveSwipePreview. The usage is the same as ShopLivePreview.
<cloud.shoplive.sdk.ShopLiveSwipePreview
android:id="@+id/swipePreview"
android:layout_width="something dimens"
android:layout_height="something dimens" /> swipePreview.start(“{accessKey}”, “{campaignKey}”)
swipePreview.setOnPreviewClickListener {
// Preview transition animation
ShopLive.setPreviewTransitionAnimation(requireActivity(), binding.preview)
ShopLive.play(requireActivity(), campaignKey)
swipePreview.release()
}
// For lifecycle observing preview
swipePreview.setLifecycleObserver(this.viewLifecycleOwner)