Skip to content

Commit

Permalink
add danmaku shoot draft
Browse files Browse the repository at this point in the history
  • Loading branch information
Predidit committed Sep 30, 2024
1 parent ed43b7d commit 872372f
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 28 deletions.
103 changes: 78 additions & 25 deletions lib/pages/player/player_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,66 @@ class _PlayerItemState extends State<PlayerItem>
}
danmakuController.onClear();
playerController.danmakuOn = !playerController.danmakuOn;
// debugPrint('弹幕开关变更为 ${playerController.danmakuOn}');
}

/// 发送弹幕 由于接口限制, 暂时未提交云端
void showShootDanmakuSheet() {
final TextEditingController textController = TextEditingController();
bool isSending = false; // 追踪是否正在发送
SmartDialog.show(
useAnimation: false,
builder: (context) {
return AlertDialog(
title: const Text('发送弹幕'),
content: StatefulBuilder(
builder: (BuildContext context, StateSetter setState) {
return TextField(
controller: textController,
);
}),
actions: [
TextButton(
onPressed: () => SmartDialog.dismiss(),
child: Text(
'取消',
style:
TextStyle(color: Theme.of(context).colorScheme.outline),
),
),
StatefulBuilder(
builder: (BuildContext context, StateSetter setState) {
return TextButton(
onPressed: isSending
? null
: () async {
final String msg = textController.text;
if (msg.isEmpty) {
SmartDialog.showToast('弹幕内容为空');
return;
} else if (msg.length > 100) {
SmartDialog.showToast('弹幕内容过长');
return;
}
setState(() {
isSending = true; // 开始发送,更新状态
});
// Todo 接口方限制

setState(() {
isSending = false; // 发送结束,更新状态
});
SmartDialog.showToast('发送成功');
danmakuController.addDanmaku(DanmakuContentItem(msg, selfSend: true));
SmartDialog.dismiss();
},
child: Text(isSending
? '发送中'
: '发送'),
);
})
],
);
});
}

// 选择倍速
Expand Down Expand Up @@ -1275,30 +1334,24 @@ class _PlayerItemState extends State<PlayerItem>
),
),
// 弹幕相关
// (playerController.androidFullscreen ==
// true &&
// playerController.danmakuOn ==
// true)
// ? IconButton(
// color: Colors.white,
// icon:
// const Icon(Icons.notes),
// onPressed: () {
// if (playerController
// .danDanmakus
// .length ==
// 0) {
// SmartDialog.showToast(
// '当前剧集不支持弹幕发送的说',
// displayType:
// SmartToastType
// .last);
// return;
// }
// showShootDanmakuSheet();
// },
// )
// : Container(),
(videoPageController.androidFullscreen &&
playerController.danmakuOn)
? IconButton(
color: Colors.white,
icon: const Icon(Icons.notes),
onPressed: () {
if (playerController
.danDanmakus.isEmpty) {
SmartDialog.showToast(
'当前剧集不支持弹幕发送的说',
displayType:
SmartToastType.last);
return;
}
showShootDanmakuSheet();
},
)
: Container(),
IconButton(
color: Colors.white,
icon: Icon(playerController.danmakuOn
Expand Down
4 changes: 2 additions & 2 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,10 @@ packages:
dependency: "direct main"
description:
name: canvas_danmaku
sha256: "128644574b5454c9290d9896a2560a751960109f902a8b943bf4b420fa09699d"
sha256: "6e220df0edd62c6787b24e00c05a24b570a716cfe9c61452f214c4ab0958374f"
url: "https://pub.dev"
source: hosted
version: "0.1.9"
version: "0.2.0"
characters:
dependency: transitive
description:
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ dependencies:
xpath_selector: ^3.0.2
xpath_selector_html_parser: ^3.0.1
webview_flutter: ^4.9.0
canvas_danmaku: ^0.1.9
canvas_danmaku: ^0.2.0
webdav_client: ^1.2.2
tray_manager: ^0.2.3
dlna_dart: ^0.0.8
Expand Down

0 comments on commit 872372f

Please sign in to comment.