跳到主要内容

发布自定义资源

提示

在 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();

参数说明

参数类型必填说明
pathString资源文件路径
tagString自定义视频资源标识

示例代码

Dart
/// 从assets目录下的资源文件创建自定义视频资源
engine.createCustomStreamFromAssetsFile(path, tag);

从本地目录创建自定义视频资源

方法

Dart
RCRTCEngine.createCustomStreamFromFile();

参数说明

参数类型必填说明
pathString本地文件路径
tagString自定义视频资源标识

示例代码

Dart
/// 从本地目录下的资源文件创建自定义视频资源
engine.createCustomStreamFromFile(path, tag);

设置自定义视频属性

方法

Dart
RCRTCEngine.setCustomStreamVideoConfig();

参数说明

参数类型必填说明
tagString自定义视频资源标识
configRCRTCVideoConfig视频配置参数

示例代码

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();

参数说明

参数类型必填说明
tagString自定义视频资源标识
viewRCRTCView预览窗口

示例代码

Dart
RCRTCView view = await RCRTCView.create();
engine.setLocalCustomStreamView(tag, view);

发布自定义视频资源

方法

Dart
RCRTCEngine.publishCustomStream();

参数说明

参数类型必填说明
tagString自定义视频资源标识

示例代码

Dart
engine.publishCustomStream(tag);

订阅远端自定义视频资源

方法

Dart
RCRTCEngine.subscribeCustomStream();

参数说明

参数类型必填说明
userIdString远端用户 ID
tagString自定义视频资源标识

示例代码

Dart
engine.subscribeCustomStream(userId, tag);

设置远端自定义视频资源预览窗口

方法

Dart
RCRTCEngine.setRemoteCustomStreamView();

参数说明

参数类型必填说明
userIdString远端用户 ID
tagString自定义视频资源标识
viewRCRTCView预览窗口

示例代码

Dart
RCRTCView view = await RCRTCView.create();
engine.setRemoteCustomStreamView(userId, tag, view);