发布自定义资源
提示
在 Android 平台至少需要调用 publish(RCRTCMediaType.audio_video)
或 publish(RCRTCMediaType.audio)
方法发布成功音频资源后,再发布自定义视频流才有效。tag 不能包含 _
和 RongCloudRTC
字符。
设置远端自定义视频资源发布监听
方法
Dart
RCRTCEngine.onRemoteCustomStreamPublished
返回值
参数 | 描述 |
---|---|
roomId | 房间 ID |
userId | 远端用户 ID |
tag | 远端自定义视频资源 tag |
type | 资源类型 |
示例代码
Dart
engine.onRemoteCustomStreamPublished = (String roomId, String userId, String tag, RCRTCMediaType type) {
// roomId 房间 ID
// userId 远端用户 ID
// tag 远端自定义视频资源 tag
// type 资源类型
print('用户 $userId 发布了自定义视频资源: $tag');
};
创建自定义视频资源
从资源目录创建自定义视频资源
方法
Dart
RCRTCEngine.createCustomStreamFromAssetsFile();
参数说明
参数 | 类型 | 必填 | 说明 |
---|---|---|---|
path | String | 是 | 资源文件路径 |
tag | String | 是 | 自定义视频资源标识 |
示例代码
Dart
/// 从assets目录下的资源文件创建自定义视频资源
engine.createCustomStreamFromAssetsFile(path, tag);
从本地目录创建自定义视频资源
方法
Dart
RCRTCEngine.createCustomStreamFromFile();
参数说明
参数 | 类型 | 必填 | 说明 |
---|---|---|---|
path | String | 是 | 本地文件路径 |
tag | String | 是 | 自定义视频资源标识 |
示例代码
Dart
/// 从本地目录下的资源文件创建自定义视频资源
engine.createCustomStreamFromFile(path, tag);
设置自定义视频属性
方法
Dart
RCRTCEngine.setCustomStreamVideoConfig();
参数说明
参数 | 类型 | 必填 | 说明 |
---|---|---|---|
tag | String | 是 | 自定义视频资源标识 |
config | RCRTCVideoConfig | 是 | 视频配置参数 |
示例代码
Dart
RCRTCVideoConfig config = RCRTCVideoConfig.create(
minBitrate: 500,
maxBitrate: 2200,
fps: RCRTCVideoFps.fps_24,
resolution: RCRTCVideoResolution.resolution_720_1280,
);
engine.setCustomStreamVideoConfig(tag, config);
设置自定义视频资源预览窗口
方法
Dart
RCRTCEngine.setLocalCustomStreamView();
参数说明
参数 | 类型 | 必填 | 说明 |
---|---|---|---|
tag | String | 是 | 自定义视频资源标识 |
view | RCRTCView | 是 | 预览窗口 |
示例代码
Dart
RCRTCView view = await RCRTCView.create();
engine.setLocalCustomStreamView(tag, view);
发布自定义视频资源
方法
Dart
RCRTCEngine.publishCustomStream();
参数说明
参数 | 类型 | 必填 | 说明 |
---|---|---|---|
tag | String | 是 | 自定义视频资源标识 |
示例代码
Dart
engine.publishCustomStream(tag);
订阅远端自定义视频资源
方法
Dart
RCRTCEngine.subscribeCustomStream();
参数说明
参数 | 类型 | 必填 | 说明 |
---|---|---|---|
userId | String | 是 | 远端用户 ID |
tag | String | 是 | 自定义视频资源标识 |
示例代码
Dart
engine.subscribeCustomStream(userId, tag);
设置远端自定义视频资源预览窗口
方法
Dart
RCRTCEngine.setRemoteCustomStreamView();
参数说明
参数 | 类型 | 必填 | 说明 |
---|---|---|---|
userId | String | 是 | 远端用户 ID |
tag | String | 是 | 自定义视频资源标识 |
view | RCRTCView | 是 | 预览窗口 |
示例代码
Dart
RCRTCView view = await RCRTCView.create();
engine.setRemoteCustomStreamView(userId, tag, view);