getPreviewURL static method
获取预览地址
'cameraIndexCode' 监控点唯一标识
'streamType' 码流类型,0主码流,1子码流
version 1表示isc1.3版本及以前,2表示isc1.4版本及以后
transmode 协议类型( 0-udp,1-tcp),默认为tcp,在protocol设置为rtsp或者rtmp时有效
isHttps 是否使用https请求,需要根据实际情况选择参数,
protocol 取流协议(应用层协议), “hik”:HIK私有协议,使用视频SDK进行播放时,传入此类型; “rtsp”:RTSP协议; “rtmp”:RTMP协议; “hls”:HLS协议(HLS协议只支持海康SDK协议、EHOME协议、ONVIF协议接入的设备;只支持H264视频编码和AAC音频编码)。 参数不填,默认为HIK协议
isHttps是否为https请求
Implementation
static Future<dynamic> getPreviewURL({
required String cameraIndexCode,
int streamType = 1,
int transmode = 1,
String protocol = '',
int version = 2,
bool isHttps = false,
}) async {
if (cameraIndexCode.isEmpty) {
return;
}
//根据版本切换地址,isc1.4之后用v2版本
var previewURLs = previewURLsV2;
if (version == 1) {
previewURLs = previewURLsV1;
}
var headers = ArtemisConfig.createHeaders(previewURLs);
///根据实际服务器情况选用http或https
String url = 'http://${ArtemisConfig.host}$previewURLs';
if (isHttps) {
url = 'https://${ArtemisConfig.host}$previewURLs';
}
Map body = Map();
body['cameraIndexCode'] = cameraIndexCode;
body['streamType'] = streamType;
body['transmode'] = transmode;
if (protocol.isNotEmpty) {
body['protocol'] = protocol;
}
Dio dio = Dio();
//增加日志
dio.interceptors.add(LogInterceptor(requestBody: true, responseBody: true));
// // 忽略SSL认证
// (dio.httpClientAdapter as DefaultHttpClientAdapter).onHttpClientCreate =
// (client) {
// client.badCertificateCallback =
// (X509Certificate cert, String host, int port) {
// return true;
// };
// };
(dio.httpClientAdapter as IOHttpClientAdapter).createHttpClient = (){
var client = HttpClient();
client.badCertificateCallback = (X509Certificate cert, String host, int port) {
return true;
};
return client;
};
dio.options.headers.addAll(headers);
Response response = await dio.post(url, data: body);
return response.data;
}