Skip to content

Commit 8073e54

Browse files
committed
Merge branch 'dev' of https://github.com/xiaoyaocz/dart_simple_live into dev
2 parents 0d38a6f + fd821db commit 8073e54

File tree

21 files changed

+385
-286
lines changed

21 files changed

+385
-286
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
simple_live_app/.vscode/settings.json
22
simple_live_tv_app/.vscode/settings.json
3+
4+
# macOS Spotlight Search index file
5+
*.DS_Store

README.md

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
1+
> ### ⚠ 本项目不提供Release安装包,请自行编译后运行测试。
22
33

44
<p align="center">
@@ -31,14 +31,7 @@
3131
- [x] Windows `BETA`
3232
- [x] MacOS `BETA`
3333
- [x] Linux `BETA`
34-
- [x] Android TV `BETA` [说明](https://github.com/xiaoyaocz/dart_simple_live/issues/338)
35-
36-
请到[Releases](https://github.com/xiaoyaocz/dart_simple_live/releases)下载最新版本,iOS请下载ipa文件自行签名安装
37-
38-
如果想体验最新功能,可前往[Actions](https://github.com/xiaoyaocz/dart_simple_live/actions)下载自动打包的开发版本
39-
40-
Windows建议下载UWP版[聚合直播](https://apps.microsoft.com/detail/9n1twg2g84vd),体验会更好
41-
34+
- [x] Android TV `BETA`
4235

4336
## 项目结构
4437

@@ -47,6 +40,10 @@ Windows建议下载UWP版[聚合直播](https://apps.microsoft.com/detail/9n1twg
4740
- `simple_live_app` 基于核心库实现的Flutter APP客户端。
4841
- `simple_live_tv_app` 基于核心库实现的Flutter Android TV客户端。
4942

43+
## 环境
44+
45+
Flutter : `3.22`
46+
5047
## 参考及引用
5148

5249
[AllLive](https://github.com/xiaoyaocz/AllLive) `本项目的C#版,有兴趣可以看看`

assets/play_config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"huya": {
3-
"user_agent": "HYSDK(Windows, 30000002)_APP(pc_exe&6080100&official)_SDK(trans&2.23.0.4969)"
3+
"user_agent": "HYSDK(Windows, 30000002)_APP(pc_exe&6090007&official)_SDK(trans&2.24.0.5157)"
44
}
55
}

simple_live_app/lib/modules/live_room/live_room_controller.dart

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -423,15 +423,15 @@ class LiveRoomController extends PlayerController with WidgetsBindingObserver {
423423
playurl = playurl.replaceAll("http://", "https://");
424424
}
425425

426-
// 初始化播放器并设置 ao 参数
427-
await initializePlayer();
428-
429-
await player.open(
430-
Media(
431-
playurl,
432-
httpHeaders: playHeaders,
433-
),
434-
);
426+
// 初始化播放器并设置 ao 参数
427+
await initializePlayer();
428+
429+
await player.open(
430+
Media(
431+
playurl,
432+
httpHeaders: playHeaders,
433+
),
434+
);
435435
Log.d("播放链接\r\n:$playurl");
436436
}
437437

@@ -1028,7 +1028,6 @@ ${error?.stackTrace}''');
10281028
}
10291029
}
10301030

1031-
10321031
// 用于启动开播时长计算和更新的函数
10331032
void startLiveDurationTimer() {
10341033
// 如果不是直播状态或者 showTime 为空,则不启动定时器
@@ -1051,7 +1050,8 @@ ${error?.stackTrace}''');
10511050
int minutes = (durationInSeconds % 3600) ~/ 60;
10521051
int seconds = durationInSeconds % 60;
10531052

1054-
String formattedDuration = '${hours.toString().padLeft(2, '0')}:${minutes.toString().padLeft(2, '0')}:${seconds.toString().padLeft(2, '0')}';
1053+
String formattedDuration =
1054+
'${hours.toString().padLeft(2, '0')}:${minutes.toString().padLeft(2, '0')}:${seconds.toString().padLeft(2, '0')}';
10551055
liveDuration.value = formattedDuration;
10561056
});
10571057
} catch (e) {

simple_live_app/lib/modules/live_room/live_room_page.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,6 @@ class LiveRoomPage extends GetView<LiveRoomController> {
234234
],
235235
),
236236
),
237-
//buildBottomActions(context),
238237
],
239238
);
240239
}

simple_live_app/lib/services/follow_service.dart

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,10 +181,20 @@ class FollowService extends GetxService {
181181
Future updateLiveStatus(FollowUser item) async {
182182
try {
183183
var site = Sites.allSites[item.siteId]!;
184-
item.liveStatus.value =
185-
(await site.liveSite.getLiveStatus(roomId: item.roomId)) ? 2 : 1;
184+
// 先只查状态
185+
var isLiving = await site.liveSite.getLiveStatus(roomId: item.roomId);
186+
item.liveStatus.value = isLiving ? 2 : 1;
187+
if (item.liveStatus.value == 2) {
188+
// 只有正在直播时才查详细信息
189+
var detail = await site.liveSite.getRoomDetail(roomId: item.roomId);
190+
item.liveStartTime = detail.showTime;
191+
} else {
192+
item.liveStartTime = null;
193+
}
186194
} catch (e) {
187195
Log.logPrint(e);
196+
item.liveStatus.value = 0;
197+
item.liveStartTime = null;
188198
} finally {
189199
updatedCount++;
190200
if (updatedCount >= followList.length) {

simple_live_app/lib/widgets/follow_user_item.dart

Lines changed: 53 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class FollowUserItem extends StatelessWidget {
4040
WidgetSpan(
4141
alignment: ui.PlaceholderAlignment.middle,
4242
child: Obx(
43-
() => Offstage(
43+
() => Offstage(
4444
offstage: item.liveStatus.value == 0,
4545
child: Row(
4646
mainAxisSize: MainAxisSize.min,
@@ -63,7 +63,7 @@ class FollowUserItem extends StatelessWidget {
6363
fontSize: 12,
6464
fontWeight: FontWeight.normal,
6565
color:
66-
item.liveStatus.value == 2 ? null : Colors.grey,
66+
item.liveStatus.value == 2 ? null : Colors.grey,
6767
),
6868
),
6969
],
@@ -88,17 +88,31 @@ class FollowUserItem extends StatelessWidget {
8888
fontSize: 12,
8989
color: Colors.grey,
9090
),
91-
),
92-
AppStyle.hGap4,
93-
Text(
94-
item.tag.length > 8 ? '${item.tag.substring(0, 8)}...' : item.tag,
95-
style: const TextStyle(
96-
fontSize: 12,
97-
color: Colors.grey,
98-
),
99-
maxLines: 1,
10091
overflow: TextOverflow.ellipsis,
10192
),
93+
if (playing)
94+
Padding(
95+
padding: AppStyle.edgeInsetsL8,
96+
child: Text(
97+
"正在观看",
98+
style: TextStyle(
99+
fontSize: 12,
100+
color: Theme.of(context).colorScheme.primary,
101+
fontWeight: FontWeight.bold,
102+
),
103+
),
104+
)
105+
else if (item.liveStatus.value == 2 && item.liveStartTime != null)
106+
Padding(
107+
padding: AppStyle.edgeInsetsL8,
108+
child: Text(
109+
'开播了${formatLiveDuration(item.liveStartTime)}',
110+
style: const TextStyle(
111+
fontSize: 12,
112+
color: Colors.grey,
113+
),
114+
),
115+
),
102116
],
103117
),
104118
trailing: playing
@@ -132,4 +146,32 @@ class FollowUserItem extends StatelessWidget {
132146
return "直播中";
133147
}
134148
}
149+
150+
String formatLiveDuration(String? startTimeStampString) {
151+
if (startTimeStampString == null ||
152+
startTimeStampString.isEmpty ||
153+
startTimeStampString == "0") {
154+
return "";
155+
}
156+
try {
157+
int startTimeStamp = int.parse(startTimeStampString);
158+
int currentTimeStamp = DateTime.now().millisecondsSinceEpoch ~/ 1000;
159+
int durationInSeconds = currentTimeStamp - startTimeStamp;
160+
161+
int hours = durationInSeconds ~/ 3600;
162+
int minutes = (durationInSeconds % 3600) ~/ 60;
163+
164+
String hourText = hours > 0 ? '${hours}小时' : '';
165+
String minuteText = minutes > 0 ? '${minutes}分钟' : '';
166+
167+
if (hours == 0 && minutes == 0) {
168+
return "不足1分钟";
169+
}
170+
171+
return '$hourText$minuteText';
172+
} catch (e) {
173+
print('格式化开播时长出错: $e');
174+
return "--小时--分钟";
175+
}
176+
}
135177
}
3.11 KB
Loading
7.73 KB
Loading
162 Bytes
Loading

0 commit comments

Comments
 (0)