createMusicMessage method

Message createMusicMessage({
  1. required int talkMode,
  2. required int toFromId,
  3. required String title,
  4. required String url,
  5. String? artist,
  6. String? cover,
  7. int? duration,
})

音乐消息(msg_type=16)。duration 为秒,省略则不写入 extra。

Implementation

Message createMusicMessage({
  required int talkMode,
  required int toFromId,
  required String title,
  required String url,
  String? artist,
  String? cover,
  int? duration,
}) {
  return Message(
    msgId: genMsgId(),
    msgType: MsgType.music,
    talkMode: talkMode,
    toFromId: toFromId,
    extra: {
      'title': title,
      'url': url,
      if (artist != null && artist.isNotEmpty) 'artist': artist,
      if (cover != null && cover.isNotEmpty) 'cover': cover,
      'duration': ?duration,
    },
    sendTime: _now(),
    status: 1,
    fromId: _store.ownerId,
  );
}