getPlayAddress method

Future<Map<String, dynamic>> getPlayAddress(
  1. String deviceSerial, {
  2. int? channelNo,
  3. int? protocol,
  4. String? code,
  5. String? password,
  6. int? expireTime,
  7. String? type,
  8. int? quality,
  9. String? startTime,
  10. String? stopTime,
  11. bool debug = false,
})

Get live stream play address for a device.

deviceSerial: The device serial number channelNo: Channel number (default: 1 for most cameras) protocol: Protocol type (0: RTMP, 1: HLS, 2: FLV, 3: WebRTC) code: Device verification code (for encrypted devices) password: Video encryption password (alias for code parameter) expireTime: Token expiration time in seconds type: Stream type (0: main stream, 1: sub stream) quality: Video quality (0: Smooth, 1: HD, 2: Ultra HD) startTime: Start time for playback (format: yyyy-MM-dd HH:mm:ss) stopTime: Stop time for playback (format: yyyy-MM-dd HH:mm:ss)

Implementation

Future<Map<String, dynamic>> getPlayAddress(
  String deviceSerial, {
  int? channelNo,
  int? protocol,
  String? code,
  String? password, // Video encryption password (alias for code)
  int? expireTime,
  String? type,
  int? quality,
  String? startTime,
  String? stopTime,
  bool debug = false, // Add debug flag
}) async {
  final body = <String, dynamic>{'deviceSerial': deviceSerial};
  if (channelNo != null) body['channelNo'] = channelNo;
  if (protocol != null) body['protocol'] = protocol;

  // Use password parameter if provided, otherwise use code
  final deviceCode = password ?? code;
  if (deviceCode != null) {
    body['code'] = deviceCode;
    if (debug) {
      print('🔐 LiveService Debug: Adding code parameter');
      print('   - Original password: $password');
      print('   - Original code: $code');
      print('   - Final deviceCode: $deviceCode');
      print('   - Code length: ${deviceCode.length}');
    }
  } else if (debug) {
    print('⚠️ LiveService Debug: NO CODE/PASSWORD provided');
  }

  if (expireTime != null) body['expireTime'] = expireTime;
  if (type != null) body['type'] = type;
  if (quality != null) body['quality'] = quality;
  if (startTime != null) body['startTime'] = startTime;
  if (stopTime != null) body['stopTime'] = stopTime;

  if (debug) {
    print('📡 LiveService Debug: API Request Body:');
    body.forEach((key, value) => print('   - $key: $value'));
  }

  return _client.post('/api/lapp/live/address/get', body);
}