4. 开始使用
4.1 导入依赖模块
Copied!
from huaweicloudsdkcore.auth.credentials import BasicCredentials, GlobalCredentials
from huaweicloudsdkcore.exceptions import exceptions
from huaweicloudsdkcore.http.http_config import HttpConfig
from huaweicloudsdklive.v1 import *
4.2 初始化认证信息, 及客户端
Copied!
def get_client(ak, sk, region):
config = HttpConfig.get_default_config()
config.timeout = 3
return LiveClient.new_builder() \
.with_http_config(config) \
.with_credentials(BasicCredentials(ak, sk)) \
.with_region(region) \
.build()
相关参数说明如下所示:
4.4 配置请求参数
以获取实时在线人数接口为例:
Copied!
request = ListLiveStreamsOnlineRequest()
request.publish_domain = "publish.example.huawei.com"
request.app = "live"
request.limit = 10
request.offset = 1
request.stream = "testStream"
相关demo说明见 5. SDK demo代码解析
4.5 发送请求
以获取实时在线人数接口为例:
Copied!
response = client.list_live_streams_online(request)
##5. SDK demo代码解析
5.1 查询直播中的流信息
demo请见stream_usage_demo.list_live_streams_online_demo()方法
5.1.1 构造请求参数
Copied!
request = ListLiveStreamsOnlineRequest()
request.publish_domain = "publish.example.huawei.com"
request.app = "live"
request.limit = 10
request.offset = 1
request.stream = "testStream"
5.1.2 发送请求
Copied!
response = client.list_live_streams_online(request)
5.1.3 接口及参数说明
请见 查询直播中的流信息
5.2 禁止直播推流
demo请见stream_forbidden_demo.create_stream_forbidden_demo()方法
5.2.1 构造请求参数
Copied!
settings = StreamForbiddenSetting()
settings.domain = "publish.example.huawei.com"
settings.app_name = "live"
settings.stream_name = "test_001"
request = CreateStreamForbiddenRequest(settings)
5.2.2 发送请求
Copied!
CreateStreamForbiddenResponse response = client.createStreamForbidden(request);
5.2.3 接口及参数说明
请见 禁止直播推流
5.3 禁推恢复
demo请见stream_forbidden_demo.delete_stream_forbidden_demo()方法
5.3.1 构造请求参数
Copied!
request = DeleteStreamForbiddenRequest()
request.domain = "publish.example.huawei.com"
request.app_name = "live"
request.stream_name = "streamTest"
5.3.2 发送请求
Copied!
response = client.delete_stream_forbidden(request)
5.3.3 接口及参数说明
请见 禁推恢复
5.4 查询禁止直播推流列表
demo请见stream_forbidden_demo.list_stream_forbidden_demo()方法
5.4.1 构造请求参数
Copied!
request = ListStreamForbiddenRequest()
request.domain = "publish.example.huawei.com"
request.app_name = "live"
request.page = 0
request.size = 10
5.4.2 发送请求
Copied!
response = client.list_stream_forbidden(request)
5.4.3 接口及参数说明
请见 禁推恢复
5.5 修改禁推属性
demo请见stream_forbidden_demo.update_stream_forbidden_demo()方法
5.5.1 构造请求参数
Copied!
settings = StreamForbiddenSetting()
settings.domain = "publish.example.huawei.com"
settings.app_name = "live"
settings.stream_name = "test_001"
request = UpdateStreamForbiddenRequest(settings)
5.5.2 发送请求
Copied!
response = client.update_stream_forbidden(request)
5.5.3 接口及参数说明
请见 修改禁推属性
直播服务流管理场景示例(Python版本)
1. 简介
华为云提供了直播服务端SDK,您可以直接集成服务端SDK来调用直播的相关API,从而实现对直播服务的快速操作。该示例展示了如何通过Python版SDK对直播流进行管理。
2. 开发前准备
3. 安装SDK
视频直播服务端SDK支持python3及以上版本。执行“ python --version” 检查当前python的版本信息。
使用服务端SDK前,您需要安装“huaweicloudsdkcore ”和 “huaweicloudsdklive”,具体的SDK版本号请参见 SDK开发中心 。
# 安装核心库 pip install huaweicloudsdkcore # 安装Live服务库 pip install huaweicloudsdklive
4. 开始使用
4.1 导入依赖模块
from huaweicloudsdkcore.auth.credentials import BasicCredentials, GlobalCredentials from huaweicloudsdkcore.exceptions import exceptions from huaweicloudsdkcore.http.http_config import HttpConfig # 导入指定Live的库 from huaweicloudsdklive.v1 import *
4.2 初始化认证信息, 及客户端
def get_client(ak, sk, region): config = HttpConfig.get_default_config() config.timeout = 3 return LiveClient.new_builder() \ .with_http_config(config) \ .with_credentials(BasicCredentials(ak, sk)) \ .with_region(region) \ .build()
相关参数说明如下所示:
ak:华为云账号Access Key。
sk:华为云账号Secret Access Key 。
service region: 服务所在区域,当前支持北京一和北京四
-- CN_NORTH_1 北京一
-- CN_NORTH_4 北京四
4.4 配置请求参数
以获取实时在线人数接口为例:
request = ListLiveStreamsOnlineRequest() request.publish_domain = "publish.example.huawei.com" request.app = "live" request.limit = 10 request.offset = 1 request.stream = "testStream"
相关demo说明见 5. SDK demo代码解析
4.5 发送请求
以获取实时在线人数接口为例:
##5. SDK demo代码解析
5.1 查询直播中的流信息
demo请见stream_usage_demo.list_live_streams_online_demo()方法
5.1.1 构造请求参数
request = ListLiveStreamsOnlineRequest() request.publish_domain = "publish.example.huawei.com" request.app = "live" request.limit = 10 request.offset = 1 request.stream = "testStream"
5.1.2 发送请求
5.1.3 接口及参数说明
请见 查询直播中的流信息
5.2 禁止直播推流
demo请见stream_forbidden_demo.create_stream_forbidden_demo()方法
5.2.1 构造请求参数
settings = StreamForbiddenSetting() settings.domain = "publish.example.huawei.com" settings.app_name = "live" settings.stream_name = "test_001" request = CreateStreamForbiddenRequest(settings)
5.2.2 发送请求
5.2.3 接口及参数说明
请见 禁止直播推流
5.3 禁推恢复
demo请见stream_forbidden_demo.delete_stream_forbidden_demo()方法
5.3.1 构造请求参数
request = DeleteStreamForbiddenRequest() request.domain = "publish.example.huawei.com" request.app_name = "live" request.stream_name = "streamTest"
5.3.2 发送请求
5.3.3 接口及参数说明
请见 禁推恢复
5.4 查询禁止直播推流列表
demo请见stream_forbidden_demo.list_stream_forbidden_demo()方法
5.4.1 构造请求参数
request = ListStreamForbiddenRequest() request.domain = "publish.example.huawei.com" request.app_name = "live" request.page = 0 request.size = 10
5.4.2 发送请求
5.4.3 接口及参数说明
请见 禁推恢复
5.5 修改禁推属性
demo请见stream_forbidden_demo.update_stream_forbidden_demo()方法
5.5.1 构造请求参数
settings = StreamForbiddenSetting() settings.domain = "publish.example.huawei.com" settings.app_name = "live" settings.stream_name = "test_001" request = UpdateStreamForbiddenRequest(settings)
5.5.2 发送请求
5.5.3 接口及参数说明
请见 修改禁推属性
6. FAQ
暂无
7. 参考
更多信息请参考 直播服务文档
8. 修订记录