toMap method

Map<String, dynamic> toMap()

Serialize to a Map for MethodChannel transport.

To align with the native TXVodDownloadMediaMsg fields, the dataSource entries are flattened to the root level; userName falls back to "default" when null.

Implementation

Map<String, dynamic> toMap() {
  final map = <String, dynamic>{};
  if (null != dataSource) {
    map['appId'] = dataSource!.appId;
    map['fileId'] = dataSource!.fileId;
    map['pSign'] = dataSource!.pSign;
    map['quality'] = dataSource!.quality;
    map['token'] = dataSource!.token;
    // Native side requires dataSource.userName to be non-null.
    map['userName'] = dataSource!.userName ?? 'default';
  }
  map['url'] = url;
  map['downloadState'] = downloadState;
  map['progress'] = progress;
  map['playPath'] = playPath;
  // Top-level userName falls back to "default" when null (aligned with native).
  map['userName'] = userName ?? 'default';
  map['duration'] = duration;
  map['playableDuration'] = playableDuration;
  map['size'] = size;
  map['downloadSize'] = downloadSize;
  map['speed'] = speed;
  map['isResourceBroken'] = isResourceBroken;
  return map;
}