getPlayAddressWithPassword method

Future<Map<String, dynamic>> getPlayAddressWithPassword(
  1. String deviceSerial,
  2. String password, {
  3. int channelNo = 1,
  4. int protocol = 1,
  5. int quality = 1,
  6. bool debug = false,
})

Get live stream with automatic encryption handling.

This method tries to get the stream without password first, and if encryption error occurs, it will retry with the provided password.

deviceSerial: The device serial number password: Video encryption password channelNo: Channel number (default: 1) protocol: Protocol type (0: RTMP, 1: HLS, 2: FLV, 3: WebRTC) quality: Video quality (0: Smooth, 1: HD, 2: Ultra HD) debug: Enable debug logging

Implementation

Future<Map<String, dynamic>> getPlayAddressWithPassword(
  String deviceSerial,
  String password, {
  int channelNo = 1,
  int protocol = 1, // Default to HLS
  int quality = 1, // Default to HD
  bool debug = false,
}) async {
  if (debug) {
    print('🔄 LiveService: getPlayAddressWithPassword called');
    print('   - deviceSerial: $deviceSerial');
    print('   - password: $password');
    print('   - password length: ${password.length}');
    print('   - channelNo: $channelNo');
    print('   - protocol: $protocol');
    print('   - quality: $quality');
  }

  try {
    // First try without password
    if (debug) print('🔍 Trying without password first...');
    return await getPlayAddress(
      deviceSerial,
      channelNo: channelNo,
      protocol: protocol,
      quality: quality,
      debug: debug,
    );
  } catch (e) {
    if (debug) print('❌ First attempt failed: $e');

    // If encryption error, retry with password
    if (e.toString().contains('60019') ||
        e.toString().contains('encryption') ||
        e.toString().contains('parameter code is empty')) {
      if (debug) print('🔐 Retrying with password...');
      return await getPlayAddress(
        deviceSerial,
        channelNo: channelNo,
        protocol: protocol,
        quality: quality,
        password: password,
        debug: debug,
      );
    } else {
      rethrow;
    }
  }
}