mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-07-01 14:50:15 +08:00
switch live stream/format/codec/url support
Signed-off-by: dom <githubaccount56556@proton.me>
This commit is contained in:
@@ -16,6 +16,7 @@ import 'package:PiliPlus/models_new/live/live_dm_info/data.dart';
|
||||
import 'package:PiliPlus/models_new/live/live_medal_wall/uinfo_medal.dart';
|
||||
import 'package:PiliPlus/models_new/live/live_room_info_h5/data.dart';
|
||||
import 'package:PiliPlus/models_new/live/live_room_play_info/codec.dart';
|
||||
import 'package:PiliPlus/models_new/live/live_room_play_info/stream.dart';
|
||||
import 'package:PiliPlus/models_new/live/live_superchat/item.dart';
|
||||
import 'package:PiliPlus/pages/common/publish/publish_route.dart';
|
||||
import 'package:PiliPlus/pages/danmaku/danmaku_model.dart';
|
||||
@@ -195,38 +196,68 @@ class LiveRoomController extends GetxController {
|
||||
_showDialog('当前直播间未开播');
|
||||
return;
|
||||
}
|
||||
if (response.playurlInfo?.playurl == null) {
|
||||
final playurl = response.playurlInfo?.playurl;
|
||||
if (playurl == null) {
|
||||
_showDialog('无法获取播放地址');
|
||||
return;
|
||||
}
|
||||
ruid = response.uid;
|
||||
if (response.roomId != null) {
|
||||
roomId = response.roomId!;
|
||||
if (response.roomId case final roomId?) {
|
||||
this.roomId = roomId;
|
||||
}
|
||||
liveTime.value = response.liveTime;
|
||||
startLiveTimer();
|
||||
isPortrait.value = response.isPortrait ?? false;
|
||||
List<CodecItem> codec =
|
||||
response.playurlInfo!.playurl!.stream!.first.format!.first.codec!;
|
||||
CodecItem item = codec.first;
|
||||
// 以服务端返回的码率为准
|
||||
currentQn = item.currentQn!;
|
||||
acceptQnList = item.acceptQn!.map((e) {
|
||||
return (
|
||||
code: e,
|
||||
desc: LiveQuality.fromCode(e)?.desc ?? e.toString(),
|
||||
);
|
||||
}).toList();
|
||||
currentQnDesc.value =
|
||||
LiveQuality.fromCode(currentQn)?.desc ?? currentQn.toString();
|
||||
videoUrl = VideoUtils.getLiveCdnUrl(item);
|
||||
await playerInit(autoFullScreenFlag: autoFullScreenFlag);
|
||||
stream = playurl.stream;
|
||||
await initLiveUrl(
|
||||
streamIndex: streamIndex,
|
||||
formatIndex: formatIndex,
|
||||
codecIndex: codecIndex,
|
||||
liveUrlIndex: liveUrlIndex,
|
||||
);
|
||||
isLoaded.value = true;
|
||||
} else {
|
||||
_showDialog(res.toString());
|
||||
}
|
||||
}
|
||||
|
||||
late List<Stream> stream;
|
||||
int streamIndex = 0;
|
||||
int formatIndex = 0;
|
||||
int codecIndex = 0;
|
||||
int liveUrlIndex = 0;
|
||||
|
||||
Future<void>? initLiveUrl({
|
||||
int streamIndex = 0,
|
||||
int formatIndex = 0,
|
||||
int codecIndex = 0,
|
||||
int liveUrlIndex = 0,
|
||||
}) {
|
||||
this.streamIndex = streamIndex;
|
||||
this.formatIndex = formatIndex;
|
||||
this.codecIndex = codecIndex;
|
||||
this.liveUrlIndex = liveUrlIndex;
|
||||
|
||||
final CodecItem item = stream
|
||||
.getOrFirst(streamIndex)
|
||||
.format
|
||||
.getOrFirst(formatIndex)
|
||||
.codec
|
||||
.getOrFirst(codecIndex);
|
||||
// 以服务端返回的码率为准
|
||||
currentQn = item.currentQn;
|
||||
acceptQnList = item.acceptQn.map((e) {
|
||||
return (
|
||||
code: e,
|
||||
desc: LiveQuality.fromCode(e)?.desc ?? e.toString(),
|
||||
);
|
||||
}).toList();
|
||||
currentQnDesc.value =
|
||||
LiveQuality.fromCode(currentQn)?.desc ?? currentQn.toString();
|
||||
videoUrl = VideoUtils.getLiveCdnUrl(item, index: liveUrlIndex);
|
||||
return playerInit();
|
||||
}
|
||||
|
||||
Future<void> queryLiveInfoH5() async {
|
||||
final res = await LiveHttp.liveRoomInfoH5(roomId: roomId);
|
||||
if (res case Success(:final response)) {
|
||||
@@ -414,10 +445,10 @@ class LiveRoomController extends GetxController {
|
||||
}
|
||||
_msgStream =
|
||||
LiveMessageStream(
|
||||
streamToken: info.token!,
|
||||
streamToken: info.token,
|
||||
roomId: roomId,
|
||||
uid: Accounts.heartbeat.mid,
|
||||
servers: info.hostList!
|
||||
servers: info.hostList
|
||||
.map((host) => 'wss://${host.host}:${host.wssPort}/sub')
|
||||
.toList(),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user