From f50b1d2bebc7b4b555e86ffba363ee634119b498 Mon Sep 17 00:00:00 2001 From: bggRGjQaUbCoE Date: Wed, 4 Jun 2025 14:51:09 +0800 Subject: [PATCH] opt live room Signed-off-by: bggRGjQaUbCoE --- lib/http/live.dart | 25 +++++++++++++----------- lib/models/live/live_room/room_info.dart | 7 +++++-- lib/pages/live_room/controller.dart | 23 ++++++++++++++++++++++ 3 files changed, 42 insertions(+), 13 deletions(-) diff --git a/lib/http/live.dart b/lib/http/live.dart index 503a95a1..dde62d16 100644 --- a/lib/http/live.dart +++ b/lib/http/live.dart @@ -103,17 +103,20 @@ class LiveHttp { } static Future liveRoomInfo({roomId, qn}) async { - var res = await Request().get(Api.liveRoomInfo, queryParameters: { - 'room_id': roomId, - 'protocol': '0, 1', - 'format': '0, 1, 2', - 'codec': '0, 1', - 'qn': qn, - 'platform': 'web', - 'ptype': 8, - 'dolby': 5, - 'panorama': 1, - }); + var res = await Request().get( + Api.liveRoomInfo, + queryParameters: { + 'room_id': roomId, + 'protocol': '0, 1', + 'format': '0, 1, 2', + 'codec': '0, 1', + 'qn': qn, + 'platform': 'web', + 'ptype': 8, + 'dolby': 5, + 'panorama': 1, + }, + ); if (res.data['code'] == 0) { return {'status': true, 'data': RoomInfoModel.fromJson(res.data['data'])}; } else { diff --git a/lib/models/live/live_room/room_info.dart b/lib/models/live/live_room/room_info.dart index 9945b004..672a8b34 100644 --- a/lib/models/live/live_room/room_info.dart +++ b/lib/models/live/live_room/room_info.dart @@ -15,7 +15,9 @@ class RoomInfoModel { roomId = json['room_id']; liveStatus = json['live_status']; liveTime = json['live_time']; - playurlInfo = PlayurlInfo.fromJson(json['playurl_info']); + playurlInfo = json['playurl_info'] == null + ? null + : PlayurlInfo.fromJson(json['playurl_info']); isPortrait = json['is_portrait']; } } @@ -28,7 +30,8 @@ class PlayurlInfo { Playurl? playurl; PlayurlInfo.fromJson(Map json) { - playurl = Playurl.fromJson(json['playurl']); + playurl = + json['playurl'] == null ? null : Playurl.fromJson(json['playurl']); } } diff --git a/lib/pages/live_room/controller.dart b/lib/pages/live_room/controller.dart index 30ae4115..bf4075fd 100644 --- a/lib/pages/live_room/controller.dart +++ b/lib/pages/live_room/controller.dart @@ -88,6 +88,29 @@ class LiveRoomController extends GetxController { var res = await LiveHttp.liveRoomInfo(roomId: roomId, qn: currentQn); if (res['status']) { RoomInfoModel data = res['data']; + if (data.liveStatus != 1) { + Get.dialog( + AlertDialog( + title: const Text('当前直播间未开播'), + actions: [ + TextButton( + onPressed: Get.back, + child: Text( + '关闭', + style: TextStyle(color: Get.theme.colorScheme.outline), + ), + ), + TextButton( + onPressed: () => Get + ..back() + ..back(), + child: const Text('退出'), + ), + ], + ), + ); + return; + } isPortrait.value = data.isPortrait ?? false; List codec = data.playurlInfo!.playurl!.stream!.first.format!.first.codec!;