3-SDK入口
- 1.PLVLiveScenesSDK
- 2.SDK Initialization
- 3.SDK Object Creation
- 4.Login to Live Page
- 5.Live Page Data Initialization
- 6.SDK Object Destruction
1.PLVLiveScenesSDK
The PLVLiveScenesSDK class is the entry point for the multi-scene SDK. It provides SDK initialization, live page data initialization, and a unified entry point and lifecycle management for each functional module.
2.SDK Initialization
You can initialize the SDK using the static method init of PLVLiveScenesSDK. For detailed usage code, refer to the PLVEntryAbility class in the demo project:
PLVLiveSceneSDK.init(context, windowStage)
3.SDK Object Creation
Before entering a new live page each time, you need to create a new SDK object. This object internally generates an sdkId associated with the live page. Subsequently, you can use the sdkId to retrieve the SDK object on that live page. For detailed usage code, refer to the PLVLoginPage class in the demo project:
// 创建 SDK 对象
const sdk: PLVLiveSceneSDK = PLVLiveSceneSDK.create()
// 获取 SDK 对象
PLVLiveSceneSDK.get(sdk.uniqueId)
4.Login to Live Page
Before entering the live page, login verification is required. You can use the loginManager method of the SDK object to log in for live streaming or replay. For detailed usage code, refer to the PLVLoginPage class in the demo project:
// 登录直播
sdk.loginManager.loginLive(userId?: string, channelId?: string, appId?: string, appSecret?: string)
// 登录回放
sdk.loginManager.loginPlayback(userId?: string, channelId?: string, appId?: string, appSecret?: string, videoId?: string)
Since each login implies entering a new live page, a new SDK object must be created before logging in. If login fails, call the destroy method of the SDK object to destroy it. After successful login, pass the uniqueId of the SDK object to the live page. Subsequently, you can use the get method of PLVLiveSceneSDK to retrieve the SDK object on the live page.
5.Live Page Data Initialization
After entering the live page, you need to initialize the live page data. When calling the initData method of the SDK object, the SDK internally initializes local resources and requests network resources. For detailed usage code, refer to the PLVLWWatchLayout class in the demo project:
// 初始化sdk数据,如果当前模块(scenes_live模块)为har类型,传getContext();如果为hsp类型,则需要传getContext().createModuleContext('模块名')
// 因sdk内部需要读取rawfile,因此这里需要传入模块的context
sdk.initData(getContext() as common.UIAbilityContext)
6.SDK Object Destruction
In addition to destroying the SDK object upon login failure, you also need to destroy the SDK object when exiting the live page to release resources. For detailed usage code, refer to the PLVLWWatchLayout class in the demo project:
sdk.destroy()
