2.快速集成
1 Account Preparation
Before integrating the Player SDK project, please register an account on the Polyv website and activate the cloud video-on-demand service.
To play on-demand videos under your account, the player must complete on-demand account authentication. For basic integration, you can use account parameters such as userId from the on-demand system. You can obtain these by logging into the on-demand backend and navigating to API Interface.
For security reasons, it is not recommended to write secretKey in plaintext into client code or app configuration files. In a production environment, it is advisable to store secretKey on your server. The server should generate the token required for playback or download and then deliver it to the client. For playback scenarios, refer to "Configure Incoming Token" in 4-Encrypted Video Copyright Protection. For download scenarios, refer to "Custom Incoming Token" in 5-Video Download.
2 Environment Requirements
| Name | Requirement |
|---|---|
| compatibleSdkVersion | >= 5.0.0(12) |
| abiFilters | arm64-v8a, x86_64 |
3 Integrating the Player Project
3.1 Importing the Common Module
Copy the common module from the demo project to the root directory of your project, and modify the project's build-profile.json5 file to add a reference to the common module:
{
"name": "common",
"srcPath": "./common"
}
3.2 Importing the Long Video Scene Module
Copy the scene_single_video module from the demo project to the root directory of your project, and modify the project's build-profile.json5 file to add a reference to the long video scene module:
{
"name": "scene_single_video",
"srcPath": "./scene_single_video"
}
3.3 Importing the Short Video Scene Module
Copy the scene_feed_video module from the demo project to the root directory of your project, and modify the project's build-profile.json5 file to add a reference to the short video scene module:
{
"name": "scene_feed_video",
"srcPath": "./scene_feed_video"
}
3.4 Configuring the Player SDK
Before configuring the Player SDK, you need to modify the module's oh-package.json5 file to add the Player SDK dependency:
{
"dependencies": {
// 播放器 SDK 对外接口依赖
"@polyvharmony/media-player-sdk": "version",
// 播放器内核依赖
"@polyvharmony/media-player-core-ijk": "version"
}
}
Components of the Player SDK, such as the playback engine, log printing, and data storage, must be configured before playing a video. You can refer to the PLVMediaPlayerStartUp class in the demo project to complete the initial configuration of the Player SDK.
// 配置全局 AppContext
PLVMediaPlayerAppContext.getInstance().setupAppContext(context)
// 配置日志
PLVCommonLogger.loggerImpl = new HiLogImpl()
// 配置数据存储
PLVKVStore.setupImplement(new PLVKVStoreOhosImpl(context))
// 配置播放内核
PLVMediaPlayerFactory.getInstance().register(PLVMediaPlayerCoreIjkProvider.getInstance())
3.5 Navigating to the Playback Page
The demo module provides three pages:
PLVMediaPlayerEntrancePageis the entry page for the project demo, demonstrating how to navigate to the long video playback page.PLVMediaPlayerSingleVideoPageis the long video playback page, supporting single video playback in both portrait and landscape orientations.PLVMediaPlayerFeedVideoPageis the short video playback page, supporting an immersive viewing experience with vertical swipe navigation.
You can navigate to the playback page from any page in your project based on actual requirements.
3.6 Parameter Modification
To play videos under your account in the demo project, you need to modify the default configuration parameters.
In the demo project, the default video data is configured in the PLVMockMediaResourceData class within the mock folder. You can modify the following parameters:
- mockAuthentication: Configure account information.
- mockViewerParam: Configure viewer information.
- setupMediaResources(): Configure video data sources.
