14
14
import com .qiniu .util .Json ;
15
15
import com .qiniu .util .StringMap ;
16
16
17
- import java .util .HashMap ;
18
17
19
18
public class CasterManager {
20
19
private final Auth auth ;
@@ -39,6 +38,7 @@ public CasterManager(Auth auth, String server, Client client) {
39
38
40
39
/**
41
40
*
41
+ * 创建云导播
42
42
* @param name 导播台name
43
43
* @param casterParams 导播台参数
44
44
* @return
@@ -47,9 +47,9 @@ public Response createCaster(String name, CasterParams casterParams) {
47
47
String url = server + "/v1/casters" ;
48
48
Gson gson = new GsonBuilder ().setPrettyPrinting ().create ();
49
49
JsonElement jsonElement = gson .toJsonTree (casterParams );
50
- jsonElement .getAsJsonObject ().addProperty ("name" ,name );
50
+ jsonElement .getAsJsonObject ().addProperty ("name" , name );
51
51
byte [] body = gson .toJson (jsonElement ).getBytes (Constants .UTF_8 );
52
- System . out . println ( body . toString () );
52
+ String a = gson . toJson ( jsonElement );
53
53
StringMap headers = auth .authorizationV2 (url , "POST" , body , Client .JsonMime );
54
54
Response response = null ;
55
55
try {
@@ -62,9 +62,10 @@ public Response createCaster(String name, CasterParams casterParams) {
62
62
63
63
/**
64
64
*
65
- * @param name 导播台name
66
- * @param marker
67
- * @param limit
65
+ * 云导播列表
66
+ * @param name 云导播名称前缀匹配
67
+ * @param marker 如果上一次返回的结果超过了单次查询限制,则会返回marker表示上一次读取到哪条记录;这一次请求带上marker后,继续从该marker后开始读取,设置为null为从头开始
68
+ * @param limit 返回的最大数量,设置为-1默认为50
68
69
* @return
69
70
*/
70
71
public Response findCasters (String name , String marker , int limit ) {
@@ -78,7 +79,7 @@ public Response findCasters(String name, String marker, int limit) {
78
79
StringMap headers = auth .authorizationV2 (url );
79
80
Response response = null ;
80
81
try {
81
- response = client .get (url ,headers );
82
+ response = client .get (url , headers );
82
83
} catch (QiniuException e ) {
83
84
e .printStackTrace ();
84
85
}
@@ -87,10 +88,11 @@ public Response findCasters(String name, String marker, int limit) {
87
88
88
89
/**
89
90
*
91
+ * 云导播信息
90
92
* @param casterId 导播台id
91
93
* @return
92
94
*/
93
- public Response getCasterInfo (String casterId ){
95
+ public Response getCasterInfo (String casterId ) {
94
96
String url = String .format ("%s/v1/casters/%s" , server , casterId );
95
97
StringMap headers = auth .authorizationV2 (url );
96
98
Response response = null ;
@@ -104,15 +106,16 @@ public Response getCasterInfo(String casterId){
104
106
105
107
/**
106
108
*
109
+ * 开启云导播
107
110
* @param casterId 导播台id
108
- * @param start 开始时间戳
109
- * @param hour 开启时长,设置为0,为1小时 ;导播台已开启时,表示延长开启时长
111
+ * @param start 开启时间,设置为-1立即启动;导播台已开启时,禁止设置开启时间,规格为时间戳(秒级)
112
+ * @param hour 开启时长,设置为-1为默认为1小时 ;导播台已开启时,表示延长开启时长 [1.~]
110
113
* @return
111
114
*/
112
115
public Response startCaster (String casterId , int start , int hour ) {
113
116
String url = String .format ("%s/v1/casters/%s/start" , server , casterId );
114
- StringMap map = new StringMap ().putWhen ("start" , start , start > 0 )
115
- .putWhen ("hour" , hour , hour > 0 );
117
+ StringMap map = new StringMap ().putWhen ("start" , start , start > 0 )
118
+ .putWhen ("hour" , hour , hour > 0 );
116
119
byte [] body = Json .encode (map ).getBytes (Constants .UTF_8 );
117
120
StringMap headers = auth .authorizationV2 (url , "POST" , body , Client .JsonMime );
118
121
Response response = null ;
@@ -126,6 +129,7 @@ public Response startCaster(String casterId, int start, int hour) {
126
129
127
130
/**
128
131
*
132
+ * 关闭云导播
129
133
* @param casterId 导播台id
130
134
* @return
131
135
*/
@@ -143,7 +147,13 @@ public Response stopCaster(String casterId) {
143
147
return response ;
144
148
}
145
149
146
- public Response deleteCaster (String casterId ){
150
+ /**
151
+ *
152
+ * 删除云导播
153
+ * @param casterId 导播台id
154
+ * @return
155
+ */
156
+ public Response deleteCaster (String casterId ) {
147
157
String url = String .format ("%s/v1/casters/%s" , server , casterId );
148
158
StringMap map = new StringMap ().putNotNull ("CasterId" , casterId );
149
159
byte [] body = Json .encode (map ).getBytes (Constants .UTF_8 );
@@ -157,7 +167,14 @@ public Response deleteCaster(String casterId){
157
167
return response ;
158
168
}
159
169
160
- public Response update (String casterId , CasterParams casterParams ){
170
+ /**
171
+ *
172
+ * 更新云导播
173
+ * @param casterId 导播台id
174
+ * @param casterParams 导播台更新参数
175
+ * @return
176
+ */
177
+ public Response update (String casterId , CasterParams casterParams ) {
161
178
String url = String .format ("%s/v1/casters/%s" , server , casterId );
162
179
byte [] body = Json .encode (casterParams ).getBytes (Constants .UTF_8 );
163
180
StringMap headers = auth .authorizationV2 (url , "POST" , body , Client .JsonMime );
@@ -170,12 +187,19 @@ public Response update(String casterId, CasterParams casterParams){
170
187
return response ;
171
188
}
172
189
173
- public Response updatePvw (String casterId , int channel , String staticKey ){
190
+ /**
191
+ *
192
+ * 更新PVW监视器频道
193
+ * @param casterId 导播台id
194
+ * @param channel 监视器频道 [0,7]
195
+ * @param staticKey 静态密钥
196
+ * @return
197
+ */
198
+ public Response updatePvw (String casterId , int channel , String staticKey ) {
174
199
String url = String .format ("%s/v1/static/casters/%s/pvw" , server , casterId );
175
200
StringMap map = new StringMap ().putNotNull ("CasterID" , casterId )
176
- .putWhen ("channel" , channel , channel >= 0 );
201
+ .putWhen ("channel" , channel , channel >= 0 );
177
202
byte [] body = Json .encode (map ).getBytes (Constants .UTF_8 );
178
-
179
203
StringMap headers = new StringMap ().put ("Authorization" , staticKey );
180
204
Response response = null ;
181
205
try {
@@ -186,12 +210,20 @@ public Response updatePvw(String casterId, int channel, String staticKey){
186
210
return response ;
187
211
}
188
212
189
- public Response updatePgm (String casterId , int channel ){
213
+ /**
214
+ *
215
+ * 更新PGM监视器频道
216
+ * @param casterId 导播台id
217
+ * @param channel 监视器频道 [0,7]
218
+ * @param staticKey 静态密钥
219
+ * @return
220
+ */
221
+ public Response updatePgm (String casterId , int channel , String staticKey ) {
190
222
String url = String .format ("%s/v1/static/casters/%s/pgm" , server , casterId );
191
223
StringMap map = new StringMap ().putNotNull ("CasterID" , casterId )
192
- .putWhen ("channel" , channel , channel >= 0 );
224
+ .putWhen ("channel" , channel , channel >= 0 );
193
225
byte [] body = Json .encode (map ).getBytes (Constants .UTF_8 );
194
- StringMap headers = auth . authorizationV2 ( url , "POST " , body , Client . JsonMime );
226
+ StringMap headers = new StringMap (). put ( "Authorization " , staticKey );
195
227
Response response = null ;
196
228
try {
197
229
response = client .post (url , body , headers , Client .JsonMime );
@@ -201,12 +233,20 @@ public Response updatePgm(String casterId, int channel){
201
233
return response ;
202
234
}
203
235
204
- public Response pvwSwitchToPgm (String casterId , boolean switchVol ){
236
+ /**
237
+ *
238
+ * PVW切换至PGM
239
+ * @param casterId 导播台id
240
+ * @param switchVol 是否同步切换音频
241
+ * @param staticKey 静态密钥
242
+ * @return
243
+ */
244
+ public Response pvwSwitchToPgm (String casterId , boolean switchVol , String staticKey ) {
205
245
String url = String .format ("%s/v1/static/casters/%s/switch" , server , casterId );
206
246
StringMap map = new StringMap ().putNotNull ("CasterID" , casterId )
207
247
.putNotNull ("switchVol" , switchVol );
208
248
byte [] body = Json .encode (map ).getBytes (Constants .UTF_8 );
209
- StringMap headers = auth . authorizationV2 ( url , "POST " , body , Client . JsonMime );
249
+ StringMap headers = new StringMap (). put ( "Authorization " , staticKey );
210
250
Response response = null ;
211
251
try {
212
252
response = client .post (url , body , headers , Client .JsonMime );
@@ -215,13 +255,25 @@ public Response pvwSwitchToPgm(String casterId, boolean switchVol){
215
255
}
216
256
return response ;
217
257
}
218
- public Response updateMonitors (String casterId , int channel , String newUrl , int vol , boolean muted ){
258
+
259
+ /**
260
+ *
261
+ * 更新监视器配置
262
+ * @param casterId 导播台id
263
+ * @param channel 监视器频道 [0,7]
264
+ * @param newUrl 监视器源流地址,支持直播流、静态视频、图片等
265
+ * @param vol 音量[0,300]
266
+ * @param muted 是否静音
267
+ * @param staticKey 静态密钥
268
+ * @return
269
+ */
270
+ public Response updateMonitors (String casterId , int channel , String newUrl , int vol , boolean muted , String staticKey ) {
219
271
String url = String .format ("%s/v1/static/casters/%s/monitors" , server , casterId );
220
272
StringMap map = new StringMap ().putNotNull ("CasterID" , casterId )
221
- .putWhen ("channel" , channel , channel >= 0 )
222
- .putNotNull ("url" ,newUrl ).putWhen ("vol" , vol , vol >= 0 ).putNotNull ("muted" ,muted );
273
+ .putWhen ("channel" , channel , channel >= 0 )
274
+ .putNotNull ("url" , newUrl ).putWhen ("vol" , vol , vol >= 0 ).putNotNull ("muted" , muted );
223
275
byte [] body = Json .encode (map ).getBytes (Constants .UTF_8 );
224
- StringMap headers = auth . authorizationV2 ( url , "POST " , body , Client . JsonMime );
276
+ StringMap headers = new StringMap (). put ( "Authorization " , staticKey );
225
277
Response response = null ;
226
278
try {
227
279
response = client .post (url , body , headers , Client .JsonMime );
@@ -230,17 +282,31 @@ public Response updateMonitors(String casterId, int channel, String newUrl, int
230
282
}
231
283
return response ;
232
284
}
233
- public Response updatePublish (String casterId , String newUrl , int ab , int vb , boolean closed , boolean emergencyMode , int emergencyChannel , int delay ){
285
+
286
+ /**
287
+ *
288
+ * 更新输出配置
289
+ * @param casterId 导播台id
290
+ * @param newUrl PGM推流地址
291
+ * @param ab [64,512] 音频码率(Kbps),默认值为64,-1为默认值
292
+ * @param vb [300,10240] 视频码率(Kbps),默认值为1000,-1为默认值
293
+ * @param closed 关闭推流
294
+ * @param emergencyMode 紧急模式开关
295
+ * @param emergencyChannel 紧急模式监视器频道,取值范围是[0,7],默认使用0频道 [0,7]
296
+ * @param delay [0,180] 延时播放,单位: 秒
297
+ * @param staticKey 静态密钥
298
+ * @return
299
+ */
300
+ public Response updatePublish (String casterId , String newUrl , int ab , int vb , boolean closed , boolean emergencyMode , int emergencyChannel , int delay , String staticKey ) {
234
301
String url = String .format ("%s/v1/static/casters/%s/publish" , server , casterId );
235
302
StringMap map = new StringMap ().putNotNull ("CasterID" , casterId )
236
- .putNotNull ("url" ,newUrl ).putWhen ("vb" , vb , vb >=300 )
237
- .putWhen ("ab" ,ab , ab >=64 )
238
- .putNotNull ("closed" ,closed ).putNotNull ("emergencyMode" ,emergencyMode )
239
- .putWhen ("emergencyChannel" , emergencyChannel , emergencyChannel >=0 )
240
- .putWhen ("delay" , delay , delay >=0 );
241
-
303
+ .putNotNull ("url" , newUrl ).putWhen ("vb" , vb , vb >= 0 )
304
+ .putWhen ("ab" , ab , ab >= 0 )
305
+ .putNotNull ("closed" , closed ).putNotNull ("emergencyMode" , emergencyMode )
306
+ .putWhen ("emergencyChannel" , emergencyChannel , emergencyChannel >= 0 )
307
+ .putWhen ("delay" , delay , delay >= 0 );
242
308
byte [] body = Json .encode (map ).getBytes (Constants .UTF_8 );
243
- StringMap headers = auth . authorizationV2 ( url , "POST " , body , Client . JsonMime );
309
+ StringMap headers = new StringMap (). put ( "Authorization " , staticKey );
244
310
Response response = null ;
245
311
try {
246
312
response = client .post (url , body , headers , Client .JsonMime );
@@ -249,10 +315,19 @@ public Response updatePublish(String casterId, String newUrl, int ab, int vb, bo
249
315
}
250
316
return response ;
251
317
}
252
- public Response changeLayout (String casterId , int layout , String staticKey ){
318
+
319
+ /**
320
+ *
321
+ * 更新PVW布局ID
322
+ * @param casterId 导播台id
323
+ * @param layout 布局ID,-1表示不使用布局
324
+ * @param staticKey 静态密钥
325
+ * @return
326
+ */
327
+ public Response changeLayout (String casterId , int layout , String staticKey ) {
253
328
String url = String .format ("%s/v1/static/casters/%s/pvw/layouts" , server , casterId );
254
329
StringMap map = new StringMap ().putNotNull ("CasterID" , casterId )
255
- .putWhen ("layout" , layout , layout >= 0 );
330
+ .putWhen ("layout" , layout , layout >= 0 );
256
331
byte [] body = Json .encode (map ).getBytes (Constants .UTF_8 );
257
332
StringMap headers = new StringMap ().put ("Authorization" , staticKey );
258
333
Response response = null ;
@@ -263,11 +338,23 @@ public Response changeLayout(String casterId, int layout, String staticKey){
263
338
}
264
339
return response ;
265
340
}
266
- public Response updateLayout (String casterId , int layout , String title , Overlay overlay , Text text , String staticKey ){
341
+
342
+ /**
343
+ *
344
+ * 更新布局配置
345
+ * @param casterId 导播台ID
346
+ * @param layout [0,7] 布局ID
347
+ * @param title 布局标题,可留空
348
+ * @param overlay 画中画配置,key为对应的监视器频道,详细参数见画中画配置(overlay)详细参数
349
+ * @param text 文字水印配置,key为文字水印标题,详细参数见文字水印配置(text)详细参数
350
+ * @param staticKey 静态密钥
351
+ * @return
352
+ */
353
+ public Response updateLayout (String casterId , int layout , String title , Overlay overlay , Text text , String staticKey ) {
267
354
String url = String .format ("%s/v1/static/casters/%s/layouts" , server , casterId );
268
355
StringMap map = new StringMap ().putNotNull ("CasterID" , casterId )
269
- .putWhen ("layout" , layout , layout >= 0 )
270
- .putNotNull ("title" ,title ).putNotNull ("overlay" , overlay ).putNotNull ("text" , text );
356
+ .putWhen ("layout" , layout , layout >= 0 )
357
+ .putNotNull ("title" , title ).putNotNull ("overlay" , overlay ).putNotNull ("text" , text );
271
358
byte [] body = Json .encode (map ).getBytes (Constants .UTF_8 );
272
359
StringMap headers = new StringMap ().put ("Authorization" , staticKey );
273
360
Response response = null ;
@@ -278,14 +365,4 @@ public Response updateLayout(String casterId, int layout, String title, Overlay
278
365
}
279
366
return response ;
280
367
}
281
-
282
-
283
-
284
-
285
-
286
-
287
-
288
-
289
-
290
-
291
368
}
0 commit comments