Skip to content

Commit faeabb6

Browse files
committed
fix(获取视频出错)
1 parent 322abde commit faeabb6

3 files changed

Lines changed: 24 additions & 12 deletions

File tree

lib/common/models/live_room.dart

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,8 @@ class LiveRoom {
2222
/// 状态
2323
bool? status;
2424

25-
/// 附加信息
2625
dynamic data;
2726

28-
/// 弹幕附加信息
2927
dynamic danmakuData;
3028

3129
/// 是否录播
@@ -67,11 +65,13 @@ class LiveRoom {
6765
watching = json['watching'] ?? '',
6866
followers = json['followers'] ?? '',
6967
platform = json['platform'] ?? '',
70-
liveStatus = LiveStatus.values[json['liveStatus'] ?? 1],
68+
liveStatus = LiveStatus.values.firstWhere((e) => e.index == json['liveStatus'], orElse: () => LiveStatus.unknown),
7169
status = json['status'] ?? false,
7270
notice = json['notice'] ?? '',
7371
introduction = json['introduction'] ?? '',
74-
isRecord = json['isRecord'] ?? false;
72+
isRecord = json['isRecord'] ?? false,
73+
data = json['data'],
74+
danmakuData = json['danmakuData'];
7575

7676
Map<String, dynamic> toJson() => <String, dynamic>{
7777
'roomId': roomId,
@@ -84,11 +84,13 @@ class LiveRoom {
8484
'watching': watching,
8585
'followers': followers,
8686
'platform': platform,
87-
'liveStatus': liveStatus?.index ?? 1,
87+
'liveStatus': liveStatus?.index ?? LiveStatus.offline.index,
8888
'isRecord': isRecord,
8989
'status': status,
9090
'notice': notice,
9191
'introduction': introduction,
92+
'data': data,
93+
'danmakuData': danmakuData,
9294
};
9395

9496
/// 创建一个新的LiveRoom实例,并用提供的值更新指定字段
@@ -139,4 +141,9 @@ class LiveRoom {
139141

140142
@override
141143
int get hashCode => Object.hash(platform, roomId);
144+
145+
@override
146+
String toString() {
147+
return 'LiveRoom{roomId: $roomId, userId: $userId, link: $link, title: $title, nick: $nick, avatar: $avatar, cover: $cover, area: $area, watching: $watching, followers: $followers, platform: $platform, introduction: $introduction, notice: $notice, status: $status, data: $data, danmakuData: $danmakuData, isRecord: $isRecord, liveStatus: $liveStatus}';
148+
}
142149
}

lib/main.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class _MyAppState extends State<MyApp> with DesktopWindowMixin {
5050
}
5151
} else {
5252
Future.delayed(Duration(seconds: 1)).then((value) async {
53-
await initGlopalPlayer();
53+
initGlopalPlayer();
5454
});
5555
}
5656
}

lib/modules/live_play/live_play_controller.dart

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ class LivePlayController extends StateController with GetSingleTickerProviderSta
2323
final String site;
2424
final StopWatchTimer _stopWatchTimer = StopWatchTimer(mode: StopWatchMode.countDown);
2525

26-
late Site currentSite = Sites.of(site);
26+
late Site currentSite;
2727

28-
late LiveDanmaku liveDanmaku = Sites.of(site).liveSite.getDanmaku();
28+
late LiveDanmaku liveDanmaku;
2929

3030
PlayerInstanceState playerState = PlayerInstanceState();
3131

@@ -51,13 +51,13 @@ class LivePlayController extends StateController with GetSingleTickerProviderSta
5151
RxList<LivePlayQuality> qualites = RxList<LivePlayQuality>();
5252

5353
/// 当前清晰度
54-
final currentQuality = 0.obs;
54+
final RxInt currentQuality = 0.obs;
5555

5656
/// 线路数据
5757
RxList<String> playUrls = RxList<String>();
5858

5959
/// 当前线路
60-
final currentLineIndex = 0.obs;
60+
final RxInt currentLineIndex = 0.obs;
6161

6262
var closeTimes = 240.obs;
6363

@@ -104,6 +104,8 @@ class LivePlayController extends StateController with GetSingleTickerProviderSta
104104
void onInit() {
105105
super.onInit();
106106
detail.value = room;
107+
currentSite = Sites.of(site);
108+
liveDanmaku = Sites.of(site).liveSite.getDanmaku();
107109
onInitPlayerState();
108110
EmojiManager().preload(site);
109111
debounce(closeTimeFlag, (callback) {
@@ -150,15 +152,16 @@ class LivePlayController extends StateController with GetSingleTickerProviderSta
150152
int line = 0,
151153
bool isReCalculate = true,
152154
}) async {
153-
SwitchableGlobalPlayer().dispose();
154155
var liveRoom = await currentSite.liveSite.getRoomDetail(
155156
roomId: detail.value!.roomId!,
156157
platform: detail.value!.platform!,
157158
);
158159
if (currentSite.id == Sites.iptvSite) {
159160
liveRoom = liveRoom.copyWith(title: detail.value!.title!, nick: detail.value!.nick!);
160161
}
162+
161163
handleCurrentLineAndQuality(reloadDataType: reloadDataType, line: line, isReCalculate: isReCalculate);
164+
detail.value = null;
162165
detail.value = liveRoom;
163166
if (liveRoom.liveStatus == LiveStatus.unknown) {
164167
if (Get.currentRoute == '/live_play') {
@@ -286,12 +289,14 @@ class LivePlayController extends StateController with GetSingleTickerProviderSta
286289
success.value = false;
287290
return;
288291
}
292+
289293
qualites.value = playQualites;
290294
if (!hasUseDefaultResolution) {
291295
String userPrefer = settings.preferResolution.value;
292296
List<String> availableQualities = playQualites.map((e) => e.quality).toList();
293297
int matchedIndex = availableQualities.indexOf(userPrefer);
294298
// 尝试直接匹配用户偏好的分辨率
299+
log(matchedIndex.toString(), name: "get_play_qualities_error");
295300
if (matchedIndex != -1) {
296301
currentQuality.value = matchedIndex;
297302
hasUseDefaultResolution = true;
@@ -311,7 +316,7 @@ class LivePlayController extends StateController with GetSingleTickerProviderSta
311316

312317
getPlayUrl();
313318
} catch (e) {
314-
SmartDialog.showToast("无法读取视频信息,请重新获取");
319+
SmartDialog.showToast("读取视频信息失败,请重新获取");
315320
success.value = false;
316321
}
317322
}

0 commit comments

Comments
 (0)