arguments = jsonDecode(methodCall.arguments);
97 |
98 | switch (methodCall.method) {
99 | case 'onPlayerListener':
100 | // 获得原始类型和参数
101 | String typeStr = arguments['type'];
102 | var params = arguments['params'];
103 |
104 | // 封装回调类型和参数
105 | QiniucloudPlayerListenerTypeEnum type;
106 |
107 | // 初始化类型
108 | for (var item in QiniucloudPlayerListenerTypeEnum.values) {
109 | if (item.toString().replaceFirst("QiniucloudPlayerListenerTypeEnum.", "") == typeStr) {
110 | type = item;
111 | break;
112 | }
113 | }
114 |
115 | // 没有找到类型就返回
116 | if (type == null) {
117 | throw MissingPluginException();
118 | }
119 |
120 | // 回调触发
121 | for (var item in listeners) {
122 | item(type, params);
123 | }
124 |
125 | break;
126 | default:
127 | throw MissingPluginException();
128 | }
129 | });
130 | }
131 |
132 | /// 添加消息监听
133 | void addListener(QiniucloudPlayerListenerValue func) {
134 | listeners.add(func);
135 | }
136 |
137 | /// 移除消息监听
138 | void removeListener(QiniucloudPlayerListenerValue func) {
139 | listeners.remove(func);
140 | }
141 | }
142 |
143 | /// 推流监听器值模型
144 | typedef QiniucloudPlayerListenerValue = void Function(QiniucloudPlayerListenerTypeEnum type, P params);
145 |
--------------------------------------------------------------------------------
/lib/controller/qiniucloud_push_view_controller.dart:
--------------------------------------------------------------------------------
1 | import 'dart:convert';
2 |
3 | import 'package:flutter/foundation.dart';
4 | import 'package:flutter/services.dart';
5 | import 'package:flutter_qiniucloud_live_plugin/entity/conference_options_entity.dart';
6 | import 'package:flutter_qiniucloud_live_plugin/entity/face_beauty_setting_entity.dart';
7 | import 'package:flutter_qiniucloud_live_plugin/entity/streaming_profile_entity.dart';
8 | import 'package:flutter_qiniucloud_live_plugin/entity/watermark_setting_entity.dart';
9 | import 'package:flutter_qiniucloud_live_plugin/enums/qiniucloud_audio_source_type_enum.dart';
10 | import 'package:flutter_qiniucloud_live_plugin/enums/qiniucloud_push_listener_type_enum.dart';
11 | import 'package:flutter_qiniucloud_live_plugin/view/qiniucloud_push_view.dart';
12 |
13 | /// 推流视图控制器
14 | class QiniucloudPushViewController {
15 | QiniucloudPushViewController(int id) : _channel = new MethodChannel('${QiniucloudPushViewState.type}_$id');
16 |
17 | final MethodChannel _channel;
18 |
19 | /// 监听器对象
20 | QiniucloudConnectedPushListener _listener;
21 |
22 | /// 添加消息监听
23 | void addListener(QiniucloudPushListenerValue func) {
24 | if (_listener == null) {
25 | _listener = QiniucloudConnectedPushListener(_channel);
26 | }
27 | _listener.addListener(func);
28 | }
29 |
30 | /// 移除消息监听
31 | void removeListener(QiniucloudPushListenerValue func) {
32 | if (_listener == null) {
33 | return;
34 | }
35 | _listener.removeListener(func);
36 | }
37 |
38 | /// 打开摄像头和麦克风采集
39 | Future resume() async {
40 | return await _channel.invokeMethod('resume');
41 | }
42 |
43 | /// 关闭摄像头和麦克风采集s
44 | Future pause() async {
45 | return await _channel.invokeMethod('pause');
46 | }
47 |
48 | /// 释放不紧要资源。
49 | Future destroy() async {
50 | return await _channel.invokeMethod('destroy');
51 | }
52 |
53 | /// 开始连麦
54 | Future startConference({
55 | @required userId, // 用户ID
56 | @required roomName, //房间名
57 | @required roomToken, //房间token
58 | ConferenceOptionsEntity conferenceOptions, // 连麦参数(仅ios有效)
59 | }) async {
60 | return await _channel.invokeMethod('startConference', {
61 | "userId": userId,
62 | "roomName": roomName,
63 | "roomToken": roomToken,
64 | "options": conferenceOptions == null ? null : conferenceOptions.toJson(),
65 | });
66 | }
67 |
68 | /// 停止连麦
69 | Future stopConference() async {
70 | return await _channel.invokeMethod('stopConference');
71 | }
72 |
73 | /// 开始推流
74 | Future startStreaming({
75 | publishUrl, // 推流地址,为null时使用全局配置上的推流地址
76 | }) async {
77 | return await _channel.invokeMethod('startStreaming', {
78 | "publishUrl": publishUrl,
79 | });
80 | }
81 |
82 | /// 停止推流
83 | Future stopStreaming() async {
84 | return await _channel.invokeMethod('stopStreaming');
85 | }
86 |
87 | /// 是否支持缩放
88 | Future isZoomSupported() async {
89 | return await _channel.invokeMethod('isZoomSupported');
90 | }
91 |
92 | /// 设置缩放比例
93 | Future setZoomValue({
94 | int value,
95 | }) async {
96 | return await _channel.invokeMethod('setZoomValue', {"value": value});
97 | }
98 |
99 | /// 获得最大缩放比例
100 | Future getMaxZoom() async {
101 | return await _channel.invokeMethod('getMaxZoom');
102 | }
103 |
104 | /// 获得当前缩放比例
105 | Future getZoom() async {
106 | return await _channel.invokeMethod('getZoom');
107 | }
108 |
109 | /// 开启闪光灯
110 | Future turnLightOn() async {
111 | return await _channel.invokeMethod('turnLightOn');
112 | }
113 |
114 | /// 关闭闪光灯
115 | Future turnLightOff() async {
116 | return await _channel.invokeMethod('turnLightOff');
117 | }
118 |
119 | /// 切换摄像头
120 | Future switchCamera() async {
121 | return await _channel.invokeMethod('switchCamera');
122 | }
123 |
124 | /// 静音
125 | Future mute({
126 | bool mute,
127 | QiniucloudAudioSourceTypeEnum audioSource,
128 | }) async {
129 | return await _channel.invokeMethod('mute', {
130 | "mute": mute,
131 | "audioSource": audioSource == null ? null : audioSource.toString().replaceAll("QiniucloudAudioSourceTypeEnum.", ""),
132 | });
133 | }
134 |
135 | /// 更新水印信息
136 | Future updateWatermarkSetting(WatermarkSettingEntity data) async {
137 | return await _channel.invokeMethod('updateWatermarkSetting', data.toJson());
138 | }
139 |
140 | /// 更新美颜信息
141 | Future updateFaceBeautySetting(FaceBeautySettingEntity data) async {
142 | return await _channel.invokeMethod('updateFaceBeautySetting', data.toJson());
143 | }
144 |
145 | /// 改变预览镜像
146 | Future setPreviewMirror({
147 | bool mirror,
148 | }) async {
149 | return await _channel.invokeMethod('setPreviewMirror', {
150 | "mirror": mirror,
151 | });
152 | }
153 |
154 | /// 改变推流镜像
155 | Future setEncodingMirror({
156 | bool mirror,
157 | }) async {
158 | return await _channel.invokeMethod('setEncodingMirror', {
159 | "mirror": mirror,
160 | });
161 | }
162 |
163 | /// 开启耳返
164 | Future startPlayback() async {
165 | return await _channel.invokeMethod('startPlayback');
166 | }
167 |
168 | /// 关闭耳返
169 | Future stopPlayback() async {
170 | return await _channel.invokeMethod('stopPlayback');
171 | }
172 |
173 | /// 更新推流参数
174 | Future setStreamingProfile({
175 | StreamingProfileEntity streamingProfile,
176 | }) async {
177 | return await _channel.invokeMethod('setStreamingProfile', {
178 | "streamingProfile": streamingProfile,
179 | });
180 | }
181 |
182 | /// 获取编码器输出的画面的高宽
183 | Future